versatile-mcmc  0.1.7
typetraits.hpp
Go to the documentation of this file.
1 
13 #ifndef VMCMC_TYPETRAITS_H_
14 #define VMCMC_TYPETRAITS_H_
15 
16 #include <type_traits>
17 #include <string>
18 #include <vector>
19 
20 namespace vmcmc {
21 
30 template<typename T>
32 {
33  using test_type = typename std::remove_const<T>::type;
34 
35  template<typename A>
36  static constexpr bool test(
37  A* pt,
38  const A* cpt = nullptr,
39  decltype( pt->begin() )* = nullptr,
40  decltype( pt->end() )* = nullptr,
41  decltype( cpt->begin() )* = nullptr,
42  decltype( cpt->end() )* = nullptr,
43 
44 // decltype( pt->clear() )* = nullptr,
45  decltype( pt->size() )* = nullptr,
46 
47  typename A::iterator* pi = nullptr,
48  typename A::const_iterator* pci = nullptr,
49  typename A::value_type* /*pv*/ = nullptr )
50  {
51  using iterator = typename A::iterator;
52  using const_iterator = typename A::const_iterator;
53  using value_type = typename A::value_type;
54 
55  return
56  ( std::is_same<decltype(pt->begin()),iterator>::value || std::is_same<decltype(pt->begin()),const_iterator>::value) &&
57  ( std::is_same<decltype(pt->end()),iterator>::value || std::is_same<decltype(pt->end()),const_iterator>::value ) &&
58  std::is_same<decltype(cpt->begin()),const_iterator>::value &&
59  std::is_same<decltype(cpt->end()),const_iterator>::value &&
60  ( std::is_same<decltype(**pi),value_type &>::value || std::is_same<decltype(**pi),value_type const &>::value ) &&
61  std::is_same<decltype(**pci),value_type const &>::value;
62  }
63 
64  template<typename A>
65  static constexpr bool test(...)
66  {
67  return false;
68  }
69 
70  static constexpr bool value = test<test_type>(nullptr);
71 };
72 
75 template <>
76 struct is_container<std::vector<bool>>
77 {
78  static constexpr bool value = true;
79 };
80 
81 template <>
82 struct is_container<std::string>
83 {
84  static constexpr bool value = false;
85 };
87 
88 }
89 
90 #endif /* VMCMC_TYPETRAITS_H_ */
Definition: algorithm.cpp:28
Typetrait checking for STL like container structure.
Definition: typetraits.hpp:31