1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

add types::joint_types

This commit is contained in:
bolero-MURAKAMI 2014-08-05 10:57:37 +09:00
parent c2ea313c6c
commit 8f5f023ed9
4 changed files with 207 additions and 1 deletions

View file

@ -15,10 +15,12 @@
#include <sprout/type/string.hpp> #include <sprout/type/string.hpp>
#include <sprout/type/uniform_types.hpp> #include <sprout/type/uniform_types.hpp>
#include <sprout/type/rebind_types.hpp> #include <sprout/type/rebind_types.hpp>
#include <sprout/type/joint_types.hpp>
#include <sprout/type/functional.hpp> #include <sprout/type/functional.hpp>
#include <sprout/type/algorithm.hpp> #include <sprout/type/algorithm.hpp>
#include <sprout/type/seq/algorithm.hpp> #include <sprout/type/seq/algorithm.hpp>
#include <sprout/type/operation.hpp> #include <sprout/type/operation.hpp>
#include <sprout/type/print.hpp> #include <sprout/type/print.hpp>
#include <sprout/type/index_tuple.hpp>
#endif // #ifndef SPROUT_TYPE_HPP #endif // #ifndef SPROUT_TYPE_HPP

View file

@ -0,0 +1,56 @@
/*=============================================================================
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_TYPE_INDEX_TUPLE_HPP
#define SPROUT_TYPE_INDEX_TUPLE_HPP
#include <sprout/config.hpp>
#include <sprout/index_tuple/integer_sequence.hpp>
#include <sprout/type/rebind_types.hpp>
namespace sprout {
namespace types {
//
// rebind_types
//
template<typename T, T... Is>
struct rebind_types<sprout::integer_sequence<T, Is...> > {
public:
template<typename... Types>
struct apply {
public:
typedef sprout::integer_sequence<T, Types::value...> type;
};
};
#if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
//
// rebind_types
//
template<sprout::index_t... Is>
struct rebind_types<sprout::index_tuple<Is...> > {
public:
template<typename... Types>
struct apply {
public:
typedef sprout::index_tuple<Types::value...> type;
};
};
template<sprout::uindex_t... Is>
struct rebind_types<sprout::uindex_tuple<Is...> > {
public:
template<typename... Types>
struct apply {
public:
typedef sprout::uindex_tuple<Types::value...> type;
};
};
#endif // #if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_INDEX_TUPLE_HPP

124
sprout/type/joint_types.hpp Normal file
View file

@ -0,0 +1,124 @@
/*=============================================================================
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_TYPE_JOINT_TYPES_HPP
#define SPROUT_TYPE_JOINT_TYPES_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/index_tuple/index_tuple.hpp>
#include <sprout/tuple/indexes.hpp>
#include <sprout/type/tuple.hpp>
#include <sprout/type/rebind_types.hpp>
namespace sprout {
namespace types {
namespace detail {
template<typename Tuple, typename Tup>
struct joint_types_impl {
private:
template<typename IndexTuple1, typename IndexTuple2>
struct apply_impl;
template<sprout::index_t... Indexes1, sprout::index_t... Indexes2>
struct apply_impl<sprout::index_tuple<Indexes1...>, sprout::index_tuple<Indexes2...> >
: public sprout::types::rebind_types<
Tuple
>::template apply<
typename sprout::types::tuple_element<Indexes1, Tuple>::type...,
typename sprout::types::tuple_element<Indexes2, Tup>::type...
>
{};
public:
typedef typename apply_impl<
typename sprout::tuple_indexes<Tuple>::type,
typename sprout::tuple_indexes<Tup>::type
>::type type;
};
template<typename Tuple>
struct joint_types_default {};
template<template<typename...> class TupleClass, typename... Ts>
struct joint_types_default<TupleClass<Ts...> > {
public:
template<typename Tup>
struct apply
: public sprout::types::detail::joint_types_impl<TupleClass<Ts...>, Tup>
{};
template<typename... Types>
struct apply<TupleClass<Types...> >
: public sprout::identity<TupleClass<Ts..., Types...> >
{};
};
template<template<typename VT, VT...> class ValueTupleClass, typename T, T... Vs>
struct joint_types_default<ValueTupleClass<T, Vs...> > {
public:
template<typename Tup>
struct apply
: public sprout::types::detail::joint_types_impl<ValueTupleClass<T, Vs...>, Tup>
{};
template<T... Values>
struct apply<ValueTupleClass<T, Values...> >
: public sprout::identity<ValueTupleClass<T, Vs..., Values...> >
{};
};
} // namespace detail
//
// joint_types
//
template<typename Tuple>
struct joint_types
: public sprout::types::detail::joint_types_default<Tuple>
{};
template<typename Tuple>
struct joint_types<Tuple const> {
public:
template<typename Tup>
struct apply {
public:
typedef typename sprout::types::joint_types<
Tuple
>::template apply<
Tup
>::type const type;
};
};
template<typename Tuple>
struct joint_types<Tuple volatile> {
public:
template<typename Tup>
struct apply {
public:
typedef typename sprout::types::joint_types<
Tuple
>::template apply<
Tup
>::type volatile type;
};
};
template<typename Tuple>
struct joint_types<Tuple const volatile> {
public:
template<typename Tup>
struct apply {
public:
typedef typename sprout::types::joint_types<
Tuple
>::template apply<
Tup
>::type const volatile type;
};
};
} // namespace types
using sprout::types::joint_types;
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_JOINT_TYPES_HPP

View file

@ -9,14 +9,38 @@
#define SPROUT_TYPE_REBIND_TYPES_HPP #define SPROUT_TYPE_REBIND_TYPES_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout { namespace sprout {
namespace types { namespace types {
namespace detail {
template<typename Tuple>
struct rebind_types_default {};
template<template<typename...> class TupleClass, typename... Ts>
struct rebind_types_default<TupleClass<Ts...> > {
public:
template<typename... Types>
struct apply
: public sprout::identity<TupleClass<Types...> >
{};
};
template<template<typename VT, VT...> class ValueTupleClass, typename T, T... Vs>
struct rebind_types_default<ValueTupleClass<T, Vs...> > {
public:
template<typename... Types>
struct apply
: public sprout::identity<ValueTupleClass<T, Types::value...> >
{};
};
} // namespace detail
// //
// rebind_types // rebind_types
// //
template<typename Tuple> template<typename Tuple>
struct rebind_types; struct rebind_types
: public sprout::types::detail::rebind_types_default<Tuple>
{};
template<typename Tuple> template<typename Tuple>
struct rebind_types<Tuple const> { struct rebind_types<Tuple const> {