Lumiera  0.pre.03
»edit your freedom«
value-type-binding.hpp
Go to the documentation of this file.
1 /*
2  VALUE-TYPE-BINDING.hpp - control type variations for custom containers
3 
4  Copyright (C)
5  2010,2024 Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
52 #ifndef LIB_META_VALUE_TYPE_BINDING_H
53 #define LIB_META_VALUE_TYPE_BINDING_H
54 
55 
56 #include "lib/error.hpp"
57 #include "lib/meta/trait.hpp"
58 
59 
60 
61 
62 namespace lib {
63 namespace meta {
64 
65  namespace { // Helper trait to detect nested value_type binding definitions
66 
67  template<typename TY>
69  {
70  template<typename X, typename XX = typename X::value_type
71  , typename XY = typename X::reference
72  , typename XZ = typename X::pointer
73  >
74  struct Probe
75  { };
76 
77  template<class X>
78  static Yes_t check(Probe<X> * );
79  template<class>
80  static No_t check(...);
81 
82  public:
83  static const bool value = (sizeof(Yes_t)==sizeof(check<TY>(0)));
84  };
85 
86  template<class X>
88  : __and_<has_nested_ValueTypeBindings< remove_reference_t<X> >
89  ,__not_<is_StringLike< remove_reference_t<X> >
90  >
91  >
92  { };
93  }
94 
95 
107  template<typename TY, typename SEL =void>
109  {
110  using value_type = typename RefTraits<TY>::Value;
111  using reference = typename RefTraits<TY>::Reference;
112  using pointer = typename RefTraits<TY>::Pointer;
113  };
114 
116  template<typename TY>
117  struct ValueTypeBinding<TY, enable_if<use_ValueTypebindings<TY>> >
118  {
119  using _SrcType = typename RefTraits<TY>::Value;
120 
121  using value_type = typename _SrcType::value_type;
122  using reference = typename _SrcType::reference;
123  using pointer = typename _SrcType::pointer;
124  };
125 
126 
127 
128 
138  template<typename T1, typename T2, bool = has_TypeResult<std::common_type<T1,T2>>()>
140  : std::false_type
141  { };
142 
143  template<typename T1, typename T2>
144  struct CommonResultYield<T1, T2, true >
145  : std::true_type
146  {
147  using _Common = std::common_type_t<T1,T2>;
148  // NOTE: unfortunately std::common_type decays (strips cv and reference)
149  static constexpr bool isConst = isConst_v<T1> or isConst_v<T2>;
150  static constexpr bool isRef = isLRef_v<T1> and isLRef_v<T2>;
151 
152  using _ConstT = std::conditional_t<isConst
153  , const _Common
154  , _Common
155  >;
156  using _ValRef = std::conditional_t<isRef
157  , std::add_lvalue_reference_t<_ConstT>
158  , std::remove_reference_t<_ConstT>
159  >;
160 
161  using ResType = _ValRef;
162  using value_type = typename RefTraits<ResType>::Value;
163  using reference = typename RefTraits<ResType>::Reference;
164  using pointer = typename RefTraits<ResType>::Pointer;
165  };
166 
167 
168 
169 }} // namespace lib::meta
170 #endif /*LIB_META_VALUE_TYPE_BINDING_H*/
Implementation namespace for support and library code.
typename enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition: meta/util.hpp:83
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition: meta/util.hpp:95
Helpers for type detection, type rewriting and metaprogramming.
Lumiera error handling (C++ interface).
Decision helper to select between returning results by value or reference.
Type re-binding helper template for creating nested typedefs usable by custom containers and iterator...