All Classes Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
basic.hpp
1 // The MIT License (MIT)
2 
3 // Copyright (c) 2012-2014 Danny Y., Rapptz
4 
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal in
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 // the Software, and to permit persons to whom the Software is furnished to do so,
10 // subject to the following conditions:
11 
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 #ifndef GEARS_CONCEPTS_BASIC_HPP
23 #define GEARS_CONCEPTS_BASIC_HPP
24 
25 #include "alias.hpp"
26 #include <utility>
27 
28 namespace gears {
29 namespace concepts {
30 namespace detail {
31 struct is_lvalue_swappable {
32  template<typename T, typename U>
33  static auto test(int) -> decltype(std::swap(std::declval<LRef<T>>(), std::declval<LRef<U>>()), std::true_type{}) {}
34  template<typename...>
35  static std::false_type test(...);
36 };
37 
38 struct is_rvalue_swappable {
39  template<typename T, typename U>
40  static auto test(int) -> decltype(std::swap(std::declval<RRef<T>>(), std::declval<RRef<U>>()), std::true_type{}) {}
41  template<typename...>
42  static std::false_type test(...);
43 };
44 } // detail
45 
73 template<typename T>
74 struct DefaultConstructible : std::is_default_constructible<Bare<T>> {};
75 
91 template<typename T>
92 struct MoveConstructible : std::is_move_constructible<Bare<T>> {};
93 
109 template<typename T>
110 struct CopyConstructible : std::is_copy_constructible<Bare<T>> {};
111 
127 template<typename T>
128 struct MoveAssignable : std::is_move_assignable<Bare<T>> {};
129 
145 template<typename T>
146 struct CopyAssignable : std::is_copy_assignable<Bare<T>> {};
147 
164 template<typename T>
165 struct Movable : And<MoveAssignable<T>, MoveConstructible<T>> {};
166 
183 template<typename T>
184 struct Copyable : And<CopyAssignable<T>, CopyConstructible<T>> {};
185 
202 template<typename T>
203 struct Assignable : And<MoveAssignable<T>, CopyAssignable<T>> {};
204 
217 template<typename T>
218 struct Destructible : std::is_destructible<Bare<T>> {};
219 
235 template<typename T, typename... Args>
236 struct Constructible : std::is_constructible<Bare<T>, Args...> {};
237 
254 template<typename T>
255 struct StandardLayout : std::is_standard_layout<Bare<T>> {};
256 
266 template<typename T>
267 struct POD : std::is_pod<Bare<T>> {};
268 
280 template<typename T>
281 struct Semiregular : And<Movable<T>, Copyable<T>, DefaultConstructible<T>> {};
282 
294 template<typename T, typename U = T>
295 struct LValueSwappable : TraitOf<detail::is_lvalue_swappable, T, U> {};
296 
308 template<typename T, typename U = T>
309 struct RValueSwappable : TraitOf<detail::is_rvalue_swappable, T, U> {};
310 
322 template<typename T, typename U = T>
323 struct Swappable : And<LValueSwappable<T, U>, RValueSwappable<T, U>> {};
324 
349 template<typename T>
350 struct ContextualBool : std::is_constructible<bool, T> {};
351 
368 template<typename T>
369 struct Integral : std::is_integral<T> {};
370 
383 template<typename T>
384 struct FloatingPoint : std::is_floating_point<T> {};
385 
396 template<typename T>
397 struct Signed : std::is_signed<T> {};
398 
409 template<typename T>
410 struct Unsigned : std::is_unsigned<T> {};
411 
422 template<typename T>
423 struct Arithmetic : std::is_arithmetic<T> {};
424 
438 template<typename T>
439 struct Fundamental : std::is_fundamental<T> {};
440 
457 template<typename T>
458 struct Compound : std::is_compound<T> {};
459 
469 template<typename T>
470 struct Pointer : std::is_pointer<T> {};
471 
481 template<typename T>
482 struct LValueReference : std::is_lvalue_reference<T> {};
483 
493 template<typename T>
494 struct RValueReference : std::is_rvalue_reference<T> {};
495 
506 template<typename T>
507 struct Reference : std::is_reference<T> {};
508 
509 namespace detail {
510 struct is_less_than_comparable {
511  template<typename T, typename U,
512  typename LT = decltype(std::declval<T&>() < std::declval<U&>()),
513  TrueIf<ContextualBool<LT>>...>
514  static std::true_type test(int);
515  template<typename...>
516  static std::false_type test(...);
517 };
518 
519 struct is_equality_comparable {
520  template<typename T, typename U,
521  typename EQ = decltype(std::declval<T&>() == std::declval<U&>()),
522  typename NE = decltype(std::declval<T&>() != std::declval<U&>()),
523  TrueIf<ContextualBool<EQ>, ContextualBool<NE>>...>
524  static std::true_type test(int);
525  template<typename...>
526  static std::false_type test(...);
527 };
528 
529 struct is_comparable {
530  template<typename T, typename U,
531  typename LT = decltype(std::declval<T&>() < std::declval<U&>()),
532  typename LE = decltype(std::declval<T&>() <= std::declval<U&>()),
533  typename GT = decltype(std::declval<T&>() > std::declval<U&>()),
534  typename GE = decltype(std::declval<T&>() >= std::declval<U&>()),
535  TrueIf<ContextualBool<LT>, ContextualBool<LE>, ContextualBool<GT>, ContextualBool<GE>>...>
536  static std::true_type test(int);
537  template<typename...>
538  static std::false_type test(...);
539 };
540 
541 template<typename Pointer>
542 struct is_np_assignable_impl {
543 private:
544  Pointer a;
545  std::nullptr_t np = nullptr;
546  const std::nullptr_t npc = nullptr;
547 public:
548  static const bool one = std::is_same<Pointer&, decltype(a = np)>();
549  static const bool two = std::is_same<Pointer&, decltype(a = npc)>();
550  static const bool three = Constructible<Pointer, std::nullptr_t>();
551  static const bool four = Constructible<Pointer, const std::nullptr_t>();
552  static const bool value = one && two && three && four;
553 };
554 
555 template<typename T>
556 struct is_np_assign : std::integral_constant<bool, is_np_assignable_impl<T>::value> {};
557 
558 struct is_incrementable {
559  template<typename T,
560  typename Po = decltype(std::declval<T&>().operator++(0)),
561  typename Pr = decltype(std::declval<T&>().operator++()),
562  TrueIf<std::is_same<Pr, LRef<T>>>...>
563  static std::true_type test(int);
564  template<typename...>
565  static std::false_type test(...);
566 };
567 
568 struct is_decrementable {
569  template<typename T,
570  typename Po = decltype(std::declval<T&>().operator--(0)),
571  typename Pr = decltype(std::declval<T&>().operator--()),
572  TrueIf<std::is_same<Pr, LRef<T>>>...>
573  static std::true_type test(int);
574  template<typename...>
575  static std::false_type test(...);
576 };
577 
578 struct is_dereferenceable {
579  template<typename T,
580  typename Re = decltype(std::declval<T&>().operator*()),
581  typename Ar = decltype(std::declval<T&>().operator->())>
582  static std::true_type test(int);
583  template<typename...>
584  static std::false_type test(...);
585 };
586 } // detail
587 
609 template<typename T, typename U = T>
610 struct LessThanComparable : TraitOf<detail::is_less_than_comparable, T, U> {};
611 
634 template<typename T, typename U = T>
635 struct EqualityComparable : TraitOf<detail::is_equality_comparable, T, U> {};
636 
648 template<typename T>
649 struct Regular : And<Semiregular<T>, EqualityComparable<T>> {};
650 
675 template<typename T, typename U = T>
676 struct Comparable : TraitOf<detail::is_comparable, T, U> {};
677 
711 template<typename T>
712 struct NullablePointer : And<DefaultConstructible<T>,
713  CopyConstructible<T>,
714  CopyAssignable<T>,
715  Destructible<T>,
716  ContextualBool<T>,
717  EqualityComparable<T, std::nullptr_t>,
718  EqualityComparable<std::nullptr_t, T>,
719  detail::is_np_assign<T>> {};
720 
738 template<typename T>
739 struct Incrementable : Or<Fundamental<T>, Pointer<T>, TraitOf<detail::is_incrementable, T>> {};
740 
758 template<typename T>
759 struct Decrementable : Or<Fundamental<T>, Pointer<T>, TraitOf<detail::is_decrementable, T>> {};
760 
779 template<typename T>
780 struct Dereferenceable : Or<Pointer<T>, TraitOf<detail::is_dereferenceable, T>> {};
781 } // concepts
782 } // gears
783 
784 #endif // GEARS_CONCEPTS_BASIC_HPP