From 1047f2f245e5afd4dcecd0b09b26168401331a45 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 30 Nov 2017 23:19:31 +0100 Subject: [PATCH] Library: decide on the overall shape of the type rebinding helper - we do strip references - we delegate to nested typedefs Hoever, we do *not* treat const or pointers in any way special -- if the user want to strip or level these, he has to do so explicitly. Initially it seemed like a good idea to do something clever here, but on the long run, such "special treatment" is just good for surprises --- src/lib/meta/value-type-binding.hpp | 76 +++++++------------ .../library/meta/value-type-binding-test.cpp | 43 +++++++++-- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/lib/meta/value-type-binding.hpp b/src/lib/meta/value-type-binding.hpp index 4e274cd23..353108502 100644 --- a/src/lib/meta/value-type-binding.hpp +++ b/src/lib/meta/value-type-binding.hpp @@ -45,10 +45,6 @@ -namespace std { - template - class shared_ptr; -} namespace lib { namespace meta { @@ -75,67 +71,51 @@ namespace meta { }; } - /** - * Type re-binding helper template for creating nested typedefs - * for use by IterAdapter or similar "Lumiera Forward Iterators". - * This trait provides a value-, reference- and pointer type, - * similar to what the STL does. - * @note client code might define specialisations - * to handle tricky situations (like const_reverse_iter) - */ template - struct TypeBinding + struct ValueTypeBinding { typedef TY value_type; typedef TY& reference; typedef TY* pointer; }; - template - struct TypeBinding - { - typedef TY value_type; - typedef TY& reference; - typedef TY* pointer; - }; - - template - struct TypeBinding - { - typedef TY value_type; - typedef const TY& reference; - typedef const TY* pointer; - }; - - template - struct TypeBinding - { - typedef TY value_type; - typedef TY& reference; - typedef TY* pointer; - }; - - template - struct TypeBinding - { - typedef TY value_type; - typedef const TY& reference; - typedef const TY* pointer; - }; - /** * specialisation for classes providing * STL style type binding definitions themselves */ template - struct TypeBinding> > + struct ValueTypeBinding> > { - typedef typename TY::pointer pointer; - typedef typename TY::reference reference; typedef typename TY::value_type value_type; + typedef typename TY::reference reference; + typedef typename TY::pointer pointer; }; + /** + * Type re-binding helper template for creating nested typedefs + * for use by IterAdapter or similar "Lumiera Forward Iterators". + * This trait provides a value-, reference- and pointer type, + * similar to what the STL does. + * @note client code might define specialisations + * to handle tricky situations (like const_reverse_iter) + */ + template + struct TypeBinding + : ValueTypeBinding + { }; + + template + struct TypeBinding + : TypeBinding + { }; + + template + struct TypeBinding + : TypeBinding + { }; + + }} // namespace lib::meta #endif /*LIB_META_VALUE_TYPE_BINDING_H*/ diff --git a/tests/library/meta/value-type-binding-test.cpp b/tests/library/meta/value-type-binding-test.cpp index 782918354..49285af96 100644 --- a/tests/library/meta/value-type-binding-test.cpp +++ b/tests/library/meta/value-type-binding-test.cpp @@ -52,8 +52,8 @@ namespace test{ }; typedef T value_type; - typedef Inner const& reference; - typedef std::shared_ptr pointer; + typedef Inner & reference; + typedef std::shared_ptr pointer; }; struct Space { }; @@ -69,44 +69,72 @@ namespace test{ struct TypeDiagnostics { using Type = X; + static constexpr auto prefix = ""; static constexpr auto postfix = ""; }; template struct TypeDiagnostics { using Type = X; + static constexpr auto prefix = ""; static constexpr auto postfix = "&"; }; template struct TypeDiagnostics { using Type = X; + static constexpr auto prefix = ""; static constexpr auto postfix = " &&"; }; template struct TypeDiagnostics { using Type = X; + static constexpr auto prefix = ""; static constexpr auto postfix = " const&"; }; template struct TypeDiagnostics { using Type = X; - static constexpr auto postfix = " const &&"; + static constexpr auto prefix = "const "; + static constexpr auto postfix = " &&"; }; template struct TypeDiagnostics { using Type = X; + static constexpr auto prefix = ""; static constexpr auto postfix = " *"; }; template + struct TypeDiagnostics + { + using Type = X; + static constexpr auto prefix = "const "; + static constexpr auto postfix = " *"; + }; + template + struct TypeDiagnostics + { + using Type = X; + static constexpr auto prefix = "const "; + static constexpr auto postfix = " * const"; + }; + template struct TypeDiagnostics { using Type = X; + static constexpr auto prefix = ""; static constexpr auto postfix = " * const"; }; + template + struct TypeDiagnostics + { + using Type = X; + static constexpr auto prefix = ""; + static constexpr auto postfix = " * const *"; + }; template inline string @@ -115,7 +143,8 @@ namespace test{ using Case = TypeDiagnostics; using Type = typename Case::Type; - return humanReadableTypeID (typeid(Type).name()) + return Case::prefix + + humanReadableTypeID (typeid(Type).name()) + Case::postfix; } @@ -166,11 +195,9 @@ namespace test{ cout << showType::reference>() <::pointer>() <::value_type>() <::reference>() <::pointer>() <::value_type>() <::reference>() <::reference>() <::pointer>() <::value_type>() <::reference>() <::pointer>() <::value_type>() <::reference>() <() <() <() <() <() <() <() <() <