diff --git a/alib2std/src/extensions/container/forward_tree.hpp b/alib2std/src/extensions/container/forward_tree.hpp index b26490aeac8aa984c0ec29b20c6e21601e56ea29..23152c48e40e72fc9345119cde39d815c310d83a 100644 --- a/alib2std/src/extensions/container/forward_tree.hpp +++ b/alib2std/src/extensions/container/forward_tree.hpp @@ -127,7 +127,7 @@ public: * \brief * The underlying iterator within some list of children. */ - typename ext::vector < forward_tree >::const_iterator node; + const forward_tree * node; /** * \brief @@ -154,7 +154,7 @@ public: * * \param n the iterator to child list */ - const_structure_iterator ( typename ext::vector < forward_tree >::const_iterator n ) : node ( n ), parents ( ), virtual_node ( false ), isEnd ( false ) { + const_structure_iterator ( const forward_tree * n ) : node ( n ), parents ( ), virtual_node ( false ), isEnd ( false ) { } /** @@ -170,9 +170,9 @@ public: const forward_tree * parent = parents.back ( ); - if ( node == parent->getChildren ( ).end ( ) ) { + if ( std::distance ( & * parent->getChildren ( ).begin ( ), node ) == std::distance ( parent->getChildren ( ).begin ( ), parent->getChildren ( ).end ( ) ) ) { // just a way to detect node == end_of_children parents.pop_back(); - node = typename ext::vector < forward_tree >::const_iterator ( parent ); + node = parent; } else { virtual_node = false; } @@ -182,11 +182,9 @@ public: isEnd = true; } } else { - typename ext::vector < forward_tree >::const_iterator newIter = node->getChildren ( ).begin ( ); - - if ( newIter != node->getChildren ( ).end ( ) ) { - parents.push_back ( & * node ); - node = newIter; + if ( ! node->getChildren ( ).empty ( ) ) { + parents.push_back ( node ); + node = & * node->getChildren ( ).begin ( ); } else { virtual_node = true; } @@ -220,12 +218,9 @@ public: virtual_node = true; isEnd = false; } else if ( virtual_node ) { - typename ext::vector < forward_tree >::const_iterator newIter = node->getChildren ( ).end ( ); - - if ( newIter != node->getChildren ( ).begin ( ) ) { - parents.push_back ( & * node ); - node = newIter; - --node; + if ( ! node->getChildren ( ).empty ( ) ) { + parents.push_back ( node ); + node = & * -- node->getChildren ( ).end ( ); } else { virtual_node = false; } @@ -233,9 +228,9 @@ public: if ( parents.size ( ) ) { const forward_tree * parent = parents.back ( ); - if ( node == parent->getChildren ( ).begin ( ) ) { + if ( node == & * parent->getChildren ( ).begin ( ) ) { parents.pop_back(); - node = typename ext::vector < forward_tree >::const_iterator ( parent ); + node = parent; } else { --node; virtual_node = true; @@ -347,7 +342,7 @@ public: * * \param n the iterator to child list */ - const_prefix_iterator ( typename ext::vector < forward_tree >::const_iterator n ) : node ( n ) { + const_prefix_iterator ( const forward_tree * n ) : node ( n ) { } /** @@ -478,7 +473,7 @@ public: * * \param n the iterator to child list */ - const_postfix_iterator ( typename ext::vector < forward_tree >::const_iterator n ) : node ( n ) { + const_postfix_iterator ( const forward_tree * n ) : node ( n ) { } /** @@ -799,7 +794,7 @@ public: * \return prefix iterator to the root */ const_prefix_iterator prefix_begin ( ) const { - return typename ext::vector < forward_tree >::const_iterator ( this ); + return const_prefix_iterator ( this ); } /** @@ -809,7 +804,7 @@ public: * \return prefix iterator one after the last node in the prefix traversal */ const_prefix_iterator prefix_end ( ) const { - const_prefix_iterator res ( typename ext::vector < forward_tree >::const_iterator ( this + 1 ) ); + const_prefix_iterator res ( this + 1 ); res.node.isEnd = true; return res; @@ -824,7 +819,7 @@ public: * \return prefix iterator to the first node in the postfix traversal */ const_postfix_iterator postfix_begin ( ) const { - const_postfix_iterator res { typename ext::vector < forward_tree >::const_iterator ( this ) }; + const_postfix_iterator res ( this ); while ( ! res.node.getVirtual ( ) ) ++res.node; @@ -838,7 +833,7 @@ public: * \return prefix iterator one after the last node in the postfix traversal */ const_postfix_iterator postfix_end ( ) const { - const_postfix_iterator res ( typename ext::vector < forward_tree >::const_iterator ( this + 1 ) ); + const_postfix_iterator res ( this + 1 ); res.node.isEnd = true; return res; @@ -853,7 +848,7 @@ public: * \return prefix iterator to the first node in the traversal */ const_structure_iterator structure_begin ( ) const { - return typename ext::vector < forward_tree >::const_iterator ( this ); + return const_structure_iterator ( this ); } /** @@ -863,7 +858,7 @@ public: * \return prefix iterator to one after the last node in the traversal */ const_structure_iterator structure_end ( ) const { - const_structure_iterator res ( typename ext::vector < forward_tree >::const_iterator ( this + 1 ) ); + const_structure_iterator res ( this + 1 ); res.isEnd = true; return res; diff --git a/alib2std/src/extensions/container/pair.hpp b/alib2std/src/extensions/container/pair.hpp index 0da5bfdd0008bcc34ef59f3e8dfc5a1023daad3d..c666da6e3fef4c9ea9b2fd351254aad5f6889ee1 100644 --- a/alib2std/src/extensions/container/pair.hpp +++ b/alib2std/src/extensions/container/pair.hpp @@ -79,11 +79,10 @@ public: }; template<typename _T1, typename _T2> -constexpr ext::pair < typename std::__decay_and_strip < _T1 >::__type, typename std::__decay_and_strip < _T2 >::__type > make_pair ( _T1 && __x, _T2 && __y ) { - typedef typename std::__decay_and_strip < _T1 >::__type __ds_type1; - typedef typename std::__decay_and_strip < _T2 >::__type __ds_type2; - typedef pair < __ds_type1, __ds_type2 > __pair_type; - return __pair_type ( std::forward < _T1 > ( __x ), std::forward < _T2 > ( __y ) ); +constexpr auto make_pair ( _T1 && __x, _T2 && __y ) { + typedef typename ext::strip_reference_wrapper < std::decay_t < _T1 > >::type __ds_type1; + typedef typename ext::strip_reference_wrapper < std::decay_t < _T2 > >::type __ds_type2; + return pair < __ds_type1, __ds_type2 > ( std::forward < _T1 > ( __x ), std::forward < _T2 > ( __y ) ); } /** diff --git a/alib2std/src/extensions/container/ptr_tuple.hpp b/alib2std/src/extensions/container/ptr_tuple.hpp index e29347b084bcea1f8ee75016b1733f4277a2a0f0..bcac673381b70064c51bbd54956baf23e0befd3f 100644 --- a/alib2std/src/extensions/container/ptr_tuple.hpp +++ b/alib2std/src/extensions/container/ptr_tuple.hpp @@ -479,9 +479,8 @@ namespace ext { * \result pointer tuple containing values from arguments */ template < typename... _Elements > -constexpr ptr_tuple < typename std::__decay_and_strip < _Elements >::__type... > make_ptr_tuple ( _Elements && ... __args ) { - typedef ptr_tuple < typename std::__decay_and_strip < _Elements >::__type... > __result_type; - return __result_type ( std::forward < _Elements > ( __args ) ... ); +constexpr auto make_ptr_tuple ( _Elements && ... __args ) { + return ptr_tuple < typename ext::strip_reference_wrapper < std::decay_t < _Elements > >::type ... > ( std::forward < _Elements > ( __args ) ... ); } } /* namespace ext */ diff --git a/alib2std/src/extensions/container/tree.hpp b/alib2std/src/extensions/container/tree.hpp index cc0c03fbd77ba6851ca91e5a7991ad1271f5077b..8dd336b6f8dfdea65396c427473d78dd651ac62b 100644 --- a/alib2std/src/extensions/container/tree.hpp +++ b/alib2std/src/extensions/container/tree.hpp @@ -152,7 +152,7 @@ public: * \brief * The underlying iterator within some list of children. */ - typename ext::vector < tree >::const_iterator node; + const tree * node; /** * \brief @@ -179,7 +179,7 @@ public: * * \param n the iterator to child list */ - const_structure_iterator ( typename ext::vector < tree >::const_iterator n ) : node ( n ), level ( 0 ), virtual_node ( false ), isEnd ( false ) { + const_structure_iterator ( const tree * n ) : node ( n ), level ( 0 ), virtual_node ( false ), isEnd ( false ) { } /** @@ -194,9 +194,9 @@ public: ++node; if ( parent != nullptr ) { - if ( node == parent->getChildren ( ).end ( ) ) { + if ( std::distance ( & * parent->getChildren ( ).begin ( ), node ) == std::distance ( parent->getChildren ( ).begin ( ), parent->getChildren ( ).end ( ) ) ) { // just a way to detect node == end_of_children --level; - node = typename ext::vector < tree >::const_iterator ( parent ); + node = parent; } else { virtual_node = false; } @@ -205,11 +205,9 @@ public: isEnd = true; } } else { - typename ext::vector < tree >::const_iterator newIter = node->getChildren ( ).begin ( ); - - if ( newIter != node->getChildren ( ).end ( ) ) { + if ( ! node->getChildren ( ).empty ( ) ) { ++level; - node = newIter; + node = & * node->getChildren ( ).begin ( ); } else { virtual_node = true; } @@ -243,12 +241,10 @@ public: virtual_node = true; isEnd = false; } else if ( virtual_node ) { - typename ext::vector < tree >::const_iterator newIter = node->getChildren ( ).end ( ); - - if ( newIter != node->getChildren ( ).begin ( ) ) { + if ( ! node->getChildren ( ).empty ( ) ) { ++level; - node = newIter; - --node; + + node = & * -- node->getChildren ( ).end ( ); } else { virtual_node = false; } @@ -256,9 +252,9 @@ public: const tree * parent = node->getParent ( ); if ( parent != nullptr ) { - if ( node == parent->getChildren ( ).begin ( ) ) { + if ( node == & * parent->getChildren ( ).begin ( ) ) { --level; - node = typename ext::vector < tree >::const_iterator ( parent ); + node = parent; } else { --node; virtual_node = true; @@ -370,7 +366,7 @@ public: * * \param n the iterator to child list */ - const_prefix_iterator ( typename ext::vector < tree >::const_iterator n ) : node ( n ) { + const_prefix_iterator ( const tree * n ) : node ( n ) { } /** @@ -501,7 +497,7 @@ public: * * \param n the iterator to child list */ - const_postfix_iterator ( typename ext::vector < tree >::const_iterator n ) : node ( n ) { + const_postfix_iterator ( const tree * n ) : node ( n ) { } /** @@ -886,7 +882,7 @@ public: * \return prefix iterator to the root */ const_prefix_iterator prefix_begin ( ) const { - return typename ext::vector < tree >::const_iterator ( this ); + return const_prefix_iterator ( this ); } /** @@ -896,7 +892,7 @@ public: * \return prefix iterator one after the last node in the prefix traversal */ const_prefix_iterator prefix_end ( ) const { - const_prefix_iterator res ( typename ext::vector < tree >::const_iterator ( this + 1 ) ); + const_prefix_iterator res ( this + 1 ); res.node.isEnd = true; return res; @@ -911,7 +907,7 @@ public: * \return prefix iterator to the first node in the postfix traversal */ const_postfix_iterator postfix_begin ( ) const { - const_postfix_iterator res { typename ext::vector < tree >::const_iterator ( this ) }; + const_postfix_iterator res ( this ); while ( ! res.node.getVirtual ( ) ) ++res.node; @@ -925,7 +921,7 @@ public: * \return prefix iterator one after the last node in the postfix traversal */ const_postfix_iterator postfix_end ( ) const { - const_postfix_iterator res ( typename ext::vector < tree >::const_iterator ( this + 1 ) ); + const_postfix_iterator res ( this + 1 ); res.node.isEnd = true; return res; @@ -940,7 +936,7 @@ public: * \return prefix iterator to the first node in the traversal */ const_structure_iterator structure_begin ( ) const { - return typename ext::vector < tree >::const_iterator ( this ); + return const_structure_iterator ( this ); } /** @@ -950,7 +946,7 @@ public: * \return prefix iterator to one after the last node in the traversal */ const_structure_iterator structure_end ( ) const { - const_structure_iterator res ( typename ext::vector < tree >::const_iterator ( this + 1 ) ); + const_structure_iterator res ( this + 1 ); res.isEnd = true; return res; diff --git a/alib2std/src/extensions/container/tuple.hpp b/alib2std/src/extensions/container/tuple.hpp index 2bf2c3f5f74103df5ab073ef12b085ad86e30d36..4bed0bc938466d22458a3876e319d31fcb3089d4 100644 --- a/alib2std/src/extensions/container/tuple.hpp +++ b/alib2std/src/extensions/container/tuple.hpp @@ -204,9 +204,8 @@ std::string to_string ( const ext::tuple < Ts ... > & value ) { * \result tuple containing values from arguments */ template < typename ... _Elements > -constexpr tuple < typename std::__decay_and_strip < _Elements >::__type... > make_tuple ( _Elements && ... __args ) { - typedef tuple < typename std::__decay_and_strip < _Elements >::__type... > __result_type; - return __result_type ( std::forward < _Elements > ( __args ) ... ); +constexpr auto make_tuple ( _Elements && ... __args ) { + return tuple < typename ext::strip_reference_wrapper < std::decay_t < _Elements > >::type ... > ( std::forward < _Elements > ( __args ) ... ); } /** diff --git a/alib2std/src/extensions/iterator.hpp b/alib2std/src/extensions/iterator.hpp index add85447591dd25ac27d9be42b2000658a5d6581..d33969f60c88b3f0c0b7a3acb5cb657212097b7e 100644 --- a/alib2std/src/extensions/iterator.hpp +++ b/alib2std/src/extensions/iterator.hpp @@ -975,7 +975,7 @@ inline constexpr void retractInternal ( RandomAccessIterator & i, Distance n, st template < typename Iterator, typename Distance > inline constexpr void retract ( Iterator & i, Distance n ) { typename std::iterator_traits < Iterator >::difference_type d = n; - retractInternal ( i, d, std::__iterator_category ( i ) ); + retractInternal ( i, d, typename std::iterator_traits < Iterator >::iterator_category ( ) ); } /** diff --git a/alib2std/src/extensions/type_traits.hpp b/alib2std/src/extensions/type_traits.hpp index be41a508b6b60d96e05d50d27fcc0f4814bc0a5b..d059f0642768c272408cd7a1cfa6816f77b0ddfc 100644 --- a/alib2std/src/extensions/type_traits.hpp +++ b/alib2std/src/extensions/type_traits.hpp @@ -203,6 +203,17 @@ namespace ext { struct casional < std::false_type, R, Ts ... > : public casional < Ts ... > { }; + // Helper which adds a reference to a type when given a reference_wrapper + template < typename T > + struct strip_reference_wrapper { + typedef T type; + }; + + template < typename T > + struct strip_reference_wrapper < std::reference_wrapper < T > > { + typedef T & type; + }; + } /* namespace ext */ #endif /* __TYPE_TRAITS_HPP_ */