From f830221c561bd9e84d4916189273f367f83b558e Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 13 Jul 2014 00:28:34 +0900 Subject: [PATCH] add tuple_traits --- sprout/tuple/tuple.hpp | 2 +- sprout/tuple/tuple/get.hpp | 9 +-- sprout/tuple/tuple/traits.hpp | 15 +++++ sprout/tuple/tuple/tuple_traits.hpp | 85 +++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 sprout/tuple/tuple/traits.hpp create mode 100644 sprout/tuple/tuple/tuple_traits.hpp diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index 8933d66a..e21225dc 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP diff --git a/sprout/tuple/tuple/get.hpp b/sprout/tuple/tuple/get.hpp index 53d26c8a..6398c2bd 100644 --- a/sprout/tuple/tuple/get.hpp +++ b/sprout/tuple/tuple/get.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -66,7 +67,7 @@ namespace sprout_tuple_detail { using sprout_adl::tuple_get; template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type& + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(T& t) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval()))) { @@ -75,15 +76,15 @@ namespace sprout_tuple_detail { template inline SPROUT_CONSTEXPR typename std::enable_if< !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, - typename sprout::tuples::tuple_element::type>::type&& + typename sprout::tuples::tuple_traits::type>::template rvalue_reference::type >::type tuple_get(T&& t) - SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval()))) + SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::type>::template tuple_get(std::declval()))) { return sprout::tuples::tuple_access_traits::template tuple_get(t); } template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const& + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(T const& t) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval()))) { diff --git a/sprout/tuple/tuple/traits.hpp b/sprout/tuple/tuple/traits.hpp new file mode 100644 index 00000000..e96dd8ad --- /dev/null +++ b/sprout/tuple/tuple/traits.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TUPLE_TUPLE_TRAITS_HPP +#define SPROUT_TUPLE_TUPLE_TRAITS_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_TUPLE_TUPLE_TRAITS_HPP diff --git a/sprout/tuple/tuple/tuple_traits.hpp b/sprout/tuple/tuple/tuple_traits.hpp new file mode 100644 index 00000000..6bd44234 --- /dev/null +++ b/sprout/tuple/tuple/tuple_traits.hpp @@ -0,0 +1,85 @@ +/*============================================================================= + Copyright (c) 2011-2014 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TUPLE_TUPLE_TUPLE_TRAITS_HPP +#define SPROUT_TUPLE_TUPLE_TUPLE_TRAITS_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // tuple_traits + // + template + struct tuple_traits { + public: + SPROUT_STATIC_CONSTEXPR std::size_t size = sprout::tuples::tuple_size::value; + public: + template + struct element + : public sprout::tuples::tuple_element + {}; + template + struct lvalue_reference + : public std::add_lvalue_reference::type> + {}; + template + struct const_lvalue_reference + : public std::add_lvalue_reference::type const> + {}; + template + struct rvalue_reference + : public std::add_rvalue_reference::type> + {}; + template + struct const_rvalue_reference + : public std::add_rvalue_reference::type const> + {}; + }; + template + SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::tuples::tuple_traits::size; + + template + struct tuple_traits { + public: + SPROUT_STATIC_CONSTEXPR std::size_t size = sprout::tuples::tuple_traits::size; + public: + template + struct element + : public sprout::tuples::tuple_traits::template element + {}; + template + struct lvalue_reference + : public sprout::tuples::tuple_traits::template const_lvalue_reference + {}; + template + struct const_lvalue_reference + : public sprout::tuples::tuple_traits::template const_lvalue_reference + {}; + template + struct rvalue_reference + : public sprout::tuples::tuple_traits::template const_rvalue_reference + {}; + template + struct const_rvalue_reference + : public sprout::tuples::tuple_traits::template const_rvalue_reference + {}; + }; + template + SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::tuples::tuple_traits::size; + } // namespace tuples + + using sprout::tuples::tuple_traits; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_TRAITS_HPP