diff --git a/sprout/fixed_container/traits.hpp b/sprout/fixed_container/traits.hpp index a732570d..fb6f4745 100644 --- a/sprout/fixed_container/traits.hpp +++ b/sprout/fixed_container/traits.hpp @@ -53,6 +53,15 @@ namespace sprout { = std::tuple_size::type>::value ; }; + template + struct fixed_container_traits + : public sprout::fixed_container_traits + { + public: + typedef typename sprout::fixed_container_traits::const_iterator iterator; + typedef typename sprout::fixed_container_traits::const_reference reference; + typedef typename sprout::fixed_container_traits::const_pointer pointer; + }; template struct fixed_container_traits : public sprout::detail::fixed_container_traits_base @@ -64,15 +73,6 @@ namespace sprout { public: SPROUT_STATIC_CONSTEXPR typename sprout::detail::fixed_container_traits_base::size_type fixed_size = N; }; - template - struct fixed_container_traits - : public sprout::fixed_container_traits - { - public: - typedef typename sprout::fixed_container_traits::const_iterator iterator; - typedef typename sprout::fixed_container_traits::const_reference reference; - typedef typename sprout::fixed_container_traits::const_pointer pointer; - }; template struct fixed_container_traits : public sprout::fixed_container_traits diff --git a/sprout/tuple/algorithm.hpp b/sprout/tuple/algorithm.hpp new file mode 100644 index 00000000..ab730dc4 --- /dev/null +++ b/sprout/tuple/algorithm.hpp @@ -0,0 +1,6 @@ +#ifndef SPROUT_TUPLE_ALGORITHM_HPP +#define SPROUT_TUPLE_ALGORITHM_HPP + +#include + +#endif // #ifndef SPROUT_TUPLE_ALGORITHM_HPP diff --git a/sprout/tuple/algorithm/copy.hpp b/sprout/tuple/algorithm/copy.hpp new file mode 100644 index 00000000..4ef367a2 --- /dev/null +++ b/sprout/tuple/algorithm/copy.hpp @@ -0,0 +1,89 @@ +#ifndef SPROUT_TUPLE_ALGORITHM_COPY_HPP +#define SPROUT_TUPLE_ALGORITHM_COPY_HPP + +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + namespace result_of { + // + // copy + // + template + struct copy { + public: + typedef typename sprout::tuples::tuple_traits::clone_type type; + }; + } // namespace result_of + + namespace detail { + template + SPROUT_CONSTEXPR inline Result copy_impl( + Tuple const& t, + InputTuple const& input, + sprout::index_tuple, + sprout::index_tuple + ) + { + return sprout::tuples::remake_clone( + t, + sprout::tuples::get(input)..., + sprout::tuples::get(t)... + ); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + (sprout::tuples::tuple_size::value > sprout::tuples::tuple_size::value), + typename sprout::tuples::result_of::copy::type + >::type copy( + Tuple const& t, + InputTuple const& input + ) + { + return sprout::tuples::detail::copy_impl::type>( + t, + input, + typename sprout::index_range::value, sprout::tuples::tuple_size::value>::type(), + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type() + ); + } + template + SPROUT_CONSTEXPR inline typename std::enable_if< + !(sprout::tuples::tuple_size::value > sprout::tuples::tuple_size::value), + typename sprout::tuples::result_of::copy::type + >::type copy( + Tuple const& t, + InputTuple const& input + ) + { + return sprout::tuples::detail::copy_impl::type>( + t, + input, + sprout::index_tuple<>(), + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type() + ); + } + } // namespace detail + // + // copy + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::result_of::copy::type copy( + Tuple const& t, + InputTuple const& input + ) + { + return sprout::tuples::detail::copy( + t, + input + ); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_ALGORITHM_COPY_HPP diff --git a/sprout/tuple/clone.hpp b/sprout/tuple/clone.hpp new file mode 100644 index 00000000..eb099559 --- /dev/null +++ b/sprout/tuple/clone.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_TUPLE_CLONE_HPP +#define SPROUT_TUPLE_CLONE_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // clone + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::tuple_traits< + typename std::remove_reference::type + >::clone_type clone(Tuple&& cont) { + typedef typename std::decay::type tuple_type; + return sprout::tuples::clone_functor().template operator()(sprout::forward(cont)); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_CLONE_HPP diff --git a/sprout/tuple/functions.hpp b/sprout/tuple/functions.hpp new file mode 100644 index 00000000..296a4b37 --- /dev/null +++ b/sprout/tuple/functions.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_TUPLE_FUNCTIONS_HPP +#define SPROUT_TUPLE_FUNCTIONS_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_TUPLE_FUNCTIONS_HPP diff --git a/sprout/tuple/make_clone.hpp b/sprout/tuple/make_clone.hpp new file mode 100644 index 00000000..ff378ba9 --- /dev/null +++ b/sprout/tuple/make_clone.hpp @@ -0,0 +1,24 @@ +#ifndef SPROUT_TUPLE_MAKE_CLONE_HPP +#define SPROUT_TUPLE_MAKE_CLONE_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // make_clone + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::tuple_traits< + typename std::remove_reference::type + >::clone_type make_clone(Args&&... args) { + typedef typename std::remove_reference::type tuple_type; + return sprout::tuples::make_clone_functor().template operator()(sprout::forward(args)...); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_MAKE_CLONE_HPP diff --git a/sprout/tuple/operation.hpp b/sprout/tuple/operation.hpp new file mode 100644 index 00000000..dc06f029 --- /dev/null +++ b/sprout/tuple/operation.hpp @@ -0,0 +1,9 @@ +#ifndef SPROUT_TUPLE_OPERATION_HPP +#define SPROUT_TUPLE_OPERATION_HPP + +#include +#include +#include +#include + +#endif // #ifndef SPROUT_TUPLE_OPERATION_HPP diff --git a/sprout/tuple/operation/append_back.hpp b/sprout/tuple/operation/append_back.hpp new file mode 100644 index 00000000..d27582af --- /dev/null +++ b/sprout/tuple/operation/append_back.hpp @@ -0,0 +1,73 @@ +#ifndef SPROUT_TUPLE_OPERATION_APPEND_BACK_HPP +#define SPROUT_TUPLE_OPERATION_APPEND_BACK_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + namespace result_of { + // + // append_back + // + template + struct append_back { + private: + template + struct apply_impl; + template + struct apply_impl, sprout::index_tuple > + : public sprout::tuples::rebind_types< + Tuple + >::template apply< + typename sprout::tuples::tuple_element::type..., + typename sprout::tuples::tuple_element::type... + > + {}; + public: + typedef typename apply_impl< + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type, + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type + >::type type; + }; + } // namespace result_of + + namespace detail { + template + SPROUT_CONSTEXPR inline Result append_back_impl( + Tuple const& t, + InputTuple const& input, + sprout::index_tuple, + sprout::index_tuple + ) + { + return sprout::tuples::remake_clone( + t, + sprout::tuples::get(t)..., + sprout::tuples::get(input)... + ); + } + } // namespace detail + // + // append_back + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::result_of::append_back::type append_back( + Tuple const& t, + InputTuple const& input + ) + { + return sprout::tuples::detail::append_back_impl::type>( + t, + input, + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type(), + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type() + ); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_OPERATION_APPEND_BACK_HPP diff --git a/sprout/tuple/operation/append_front.hpp b/sprout/tuple/operation/append_front.hpp new file mode 100644 index 00000000..2028991b --- /dev/null +++ b/sprout/tuple/operation/append_front.hpp @@ -0,0 +1,73 @@ +#ifndef SPROUT_TUPLE_OPERATION_APPEND_FRONT_HPP +#define SPROUT_TUPLE_OPERATION_APPEND_FRONT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + namespace result_of { + // + // append_front + // + template + struct append_front { + private: + template + struct apply_impl; + template + struct apply_impl, sprout::index_tuple > + : public sprout::tuples::rebind_types< + Tuple + >::template apply< + typename sprout::tuples::tuple_element::type..., + typename sprout::tuples::tuple_element::type... + > + {}; + public: + typedef typename apply_impl< + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type, + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type + >::type type; + }; + } // namespace result_of + + namespace detail { + template + SPROUT_CONSTEXPR inline Result append_front_impl( + Tuple const& t, + InputTuple const& input, + sprout::index_tuple, + sprout::index_tuple + ) + { + return sprout::tuples::remake_clone( + t, + sprout::tuples::get(input)..., + sprout::tuples::get(t)... + ); + } + } // namespace detail + // + // append_front + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::result_of::append_front::type append_front( + Tuple const& t, + InputTuple const& input + ) + { + return sprout::tuples::detail::append_front_impl::type>( + t, + input, + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type(), + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type() + ); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_OPERATION_APPEND_FRONT_HPP diff --git a/sprout/tuple/operation/push_back.hpp b/sprout/tuple/operation/push_back.hpp new file mode 100644 index 00000000..a69a370d --- /dev/null +++ b/sprout/tuple/operation/push_back.hpp @@ -0,0 +1,70 @@ +#ifndef SPROUT_TUPLE_OPERATION_PUSH_BACK_HPP +#define SPROUT_TUPLE_OPERATION_PUSH_BACK_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + namespace result_of { + // + // push_back + // + template + struct push_back { + private: + template + struct apply_impl; + template + struct apply_impl> + : public sprout::tuples::rebind_types< + Tuple + >::template apply< + typename sprout::tuples::tuple_element::type..., + T + > + {}; + public: + typedef typename apply_impl< + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type + >::type type; + }; + } // namespace result_of + + namespace detail { + template + SPROUT_CONSTEXPR inline Result push_back_impl( + Tuple const& t, + T const& v, + sprout::index_tuple + ) + { + return sprout::tuples::remake_clone( + t, + sprout::tuples::get(t)..., + v + ); + } + } // namespace detail + // + // push_back + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::result_of::push_back::type push_back( + Tuple const& t, + T const& v + ) + { + return sprout::tuples::detail::push_back_impl::type>( + t, + v, + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type() + ); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_OPERATION_PUSH_BACK_HPP diff --git a/sprout/tuple/operation/push_front.hpp b/sprout/tuple/operation/push_front.hpp new file mode 100644 index 00000000..8592a9a7 --- /dev/null +++ b/sprout/tuple/operation/push_front.hpp @@ -0,0 +1,70 @@ +#ifndef SPROUT_TUPLE_OPERATION_PUSH_FRONT_HPP +#define SPROUT_TUPLE_OPERATION_PUSH_FRONT_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + namespace result_of { + // + // push_front + // + template + struct push_front { + private: + template + struct apply_impl; + template + struct apply_impl> + : public sprout::tuples::rebind_types< + Tuple + >::template apply< + T, + typename sprout::tuples::tuple_element::type... + > + {}; + public: + typedef typename apply_impl< + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type + >::type type; + }; + } // namespace result_of + + namespace detail { + template + SPROUT_CONSTEXPR inline Result push_front_impl( + Tuple const& t, + T const& v, + sprout::index_tuple + ) + { + return sprout::tuples::remake_clone( + t, + v, + sprout::tuples::get(t)... + ); + } + } // namespace detail + // + // push_front + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::result_of::push_front::type push_front( + Tuple const& t, + T const& v + ) + { + return sprout::tuples::detail::push_front_impl::type>( + t, + v, + typename sprout::index_range<0, sprout::tuples::tuple_size::value>::type() + ); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_OPERATION_PUSH_FRONT_HPP diff --git a/sprout/tuple/remake_clone.hpp b/sprout/tuple/remake_clone.hpp new file mode 100644 index 00000000..fee6e357 --- /dev/null +++ b/sprout/tuple/remake_clone.hpp @@ -0,0 +1,31 @@ +#ifndef SPROUT_TUPLE_REMAKE_CLONE_HPP +#define SPROUT_TUPLE_REMAKE_CLONE_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // remake_clone + // + template + SPROUT_CONSTEXPR inline typename sprout::tuples::tuple_traits< + typename std::remove_reference::type + >::clone_type remake_clone( + Other&& other, + Args&&... args + ) + { + typedef typename std::remove_reference::type tuple_type; + return sprout::tuples::remake_clone_functor().template operator()( + sprout::forward(other), + sprout::forward(args)... + ); + } + } // namespace tuples +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_REMAKE_CLONE_HPP diff --git a/sprout/tuple/traits.hpp b/sprout/tuple/traits.hpp new file mode 100644 index 00000000..eab70a34 --- /dev/null +++ b/sprout/tuple/traits.hpp @@ -0,0 +1,99 @@ +#ifndef SPROUT_TUPLE_TRAITS_HPP +#define SPROUT_TUPLE_TRAITS_HPP + +#include +#include + +namespace sprout { + namespace tuples { + // + // tuple_traits + // + template + struct tuple_traits { + public: + typedef Tuple internal_type; + typedef Tuple clone_type; + }; + template + struct tuple_traits + : public sprout::tuples::tuple_traits + {}; + + // + // rebind_types + // + template + struct rebind_types { + public: + template + struct apply; + }; + template + struct rebind_types > { + public: + template + struct apply { + public: + typedef sprout::tuples::tuple type; + }; + }; + + // + // clone_functor + // + template + struct clone_functor { + public: + template + SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::clone_type operator()(Other&& t) const { + return typename sprout::tuples::tuple_traits::clone_type(sprout::forward(t)); + } + }; + template + struct clone_functor + : public sprout::tuples::clone_functor + {}; + + // + // make_clone_functor + // + template + struct make_clone_functor { + public: + template + SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::clone_type operator()(Args&&... args) const { + return typename sprout::tuples::tuple_traits::clone_type(sprout::forward(args)...); + } + }; + template + struct make_clone_functor + : public sprout::tuples::make_clone_functor + {}; + + // + // remake_clone_functor + // + template + struct remake_clone_functor { + public: + template + SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::clone_type operator()( + Other&& other, + Args&&... args + ) const + { + return sprout::tuples::make_clone_functor().template operator()(sprout::forward(args)...); + } + }; + template + struct remake_clone_functor + : public sprout::tuples::remake_clone_functor + {}; + } // namespace tuples + + using sprout::tuples::tuple_traits; + using sprout::tuples::rebind_types; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_TRAITS_HPP