Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
62namespace lib {
63namespace 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>
114
116 template<typename TY>
117 struct ValueTypeBinding<TY, enable_if<use_ValueTypebindings<TY>> >
118 {
120
121 using value_type = _SrcType::value_type;
122 using reference = _SrcType::reference;
123 using pointer = _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>
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
165 };
166
167
168
169}} // namespace lib::meta
170#endif /*LIB_META_VALUE_TYPE_BINDING_H*/
Lumiera error handling (C++ interface).
char Yes_t
helper types to detect the overload resolution chosen by the compiler
Definition meta/util.hpp:99
RefTraits< TY >::Reference reference
RefTraits< TY >::Value value_type
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
RefTraits< TY >::Pointer pointer
Type re-binding helper template for creating nested typedefs usable by custom containers and iterator...
Implementation namespace for support and library code.
std::conditional_t< isRef, std::add_lvalue_reference_t< _ConstT >, std::remove_reference_t< _ConstT > > _ValRef
std::conditional_t< isConst, const _Common, _Common > _ConstT
Decision helper to select between returning results by value or reference.
Helpers for type detection, type rewriting and metaprogramming.