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

add make_array, make_string variation (remove make_string_as)

This commit is contained in:
bolero-MURAKAMI 2016-04-03 21:00:55 +09:00
parent f0ec89c423
commit 478c21a300
5 changed files with 108 additions and 22 deletions

View file

@ -30,6 +30,11 @@ namespace sprout {
make_array(Types&&... args) { make_array(Types&&... args) {
return sprout::array<typename std::remove_cv<T>::type, sizeof...(Types)>{{T(SPROUT_FORWARD(Types, args))...}}; return sprout::array<typename std::remove_cv<T>::type, sizeof...(Types)>{{T(SPROUT_FORWARD(Types, args))...}};
} }
template<typename T, std::size_t N, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename std::remove_cv<T>::type, N>
make_array(Types&&... args) {
return sprout::array<typename std::remove_cv<T>::type, N>{{T(SPROUT_FORWARD(Types, args))...}};
}
template<sprout::detail::make_array_t = sprout::detail::make_array_in_common_elements, typename... Types> template<sprout::detail::make_array_t = sprout::detail::make_array_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)> inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
make_array(Types&&... args) { make_array(Types&&... args) {
@ -37,6 +42,13 @@ namespace sprout {
typedef sprout::array<value_type, sizeof...(Types)> type; typedef sprout::array<value_type, sizeof...(Types)> type;
return type{{value_type(SPROUT_FORWARD(Types, args))...}}; return type{{value_type(SPROUT_FORWARD(Types, args))...}};
} }
template<std::size_t N, sprout::detail::make_array_t = sprout::detail::make_array_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, N>
make_array(Types&&... args) {
typedef typename sprout::common_decay<Types...>::type value_type;
typedef sprout::array<value_type, N> type;
return type{{value_type(SPROUT_FORWARD(Types, args))...}};
}
// //
// make_array_without_narrowing // make_array_without_narrowing
@ -46,6 +58,11 @@ namespace sprout {
make_array_without_narrowing(Types&&... args) { make_array_without_narrowing(Types&&... args) {
return sprout::array<typename std::remove_cv<T>::type, sizeof...(Types)>{{SPROUT_FORWARD(Types, args)...}}; return sprout::array<typename std::remove_cv<T>::type, sizeof...(Types)>{{SPROUT_FORWARD(Types, args)...}};
} }
template<typename T, std::size_t N, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename std::remove_cv<T>::type, N>
make_array_without_narrowing(Types&&... args) {
return sprout::array<typename std::remove_cv<T>::type, N>{{SPROUT_FORWARD(Types, args)...}};
}
template<sprout::detail::make_array_t = sprout::detail::make_array_in_common_elements, typename... Types> template<sprout::detail::make_array_t = sprout::detail::make_array_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)> inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
make_array_without_narrowing(Types&&... args) { make_array_without_narrowing(Types&&... args) {
@ -53,6 +70,13 @@ namespace sprout {
typedef sprout::array<value_type, sizeof...(Types)> type; typedef sprout::array<value_type, sizeof...(Types)> type;
return type{{SPROUT_FORWARD(Types, args)...}}; return type{{SPROUT_FORWARD(Types, args)...}};
} }
template<std::size_t N, sprout::detail::make_array_t = sprout::detail::make_array_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, N>
make_array_without_narrowing(Types&&... args) {
typedef typename sprout::common_decay<Types...>::type value_type;
typedef sprout::array<value_type, N> type;
return type{{SPROUT_FORWARD(Types, args)...}};
}
// //
// make_common_array // make_common_array
@ -62,6 +86,11 @@ namespace sprout {
make_common_array(Types&&... args) { make_common_array(Types&&... args) {
return sprout::make_array(SPROUT_FORWARD(Types, args)...); return sprout::make_array(SPROUT_FORWARD(Types, args)...);
} }
template<std::size_t N, typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, N>
make_common_array(Types&&... args) {
return sprout::make_array<N>(SPROUT_FORWARD(Types, args)...);
}
// //
// convert_array // convert_array

View file

@ -16,33 +16,55 @@
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
namespace sprout { namespace sprout {
namespace detail {
enum make_string_t {
make_string_in_head_type
};
} // namespace detail
// //
// make_string // make_string
// //
template<typename T, typename... Types>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, 1 + sizeof...(Types)>
make_string(T&& t, Types&&... args) {
typedef sprout::detail::make_construct_impl<
sprout::basic_string<typename std::decay<T>::type, 1 + sizeof...(Types)>
> impl_type;
return impl_type::make(SPROUT_FORWARD(T, t), SPROUT_FORWARD(Types, args)...);
}
//
// make_string_as
//
template<typename T> template<typename T>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, 0> inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, 0>
make_string_as() { make_string() {
return sprout::basic_string<typename std::decay<T>::type, 0>(); return sprout::basic_string<typename std::decay<T>::type, 0>();
} }
template<typename T, typename... Types> template<typename T, std::size_t N>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, sizeof...(Types)> inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, N>
make_string_as(Types&&... args) { make_string() {
return sprout::basic_string<typename std::decay<T>::type, N>();
}
template<typename T, typename Head, typename... Tail>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, 1 + sizeof...(Tail)>
make_string(Head&& head, Tail&&... tail) {
typedef sprout::detail::make_construct_impl< typedef sprout::detail::make_construct_impl<
sprout::basic_string<typename std::decay<T>::type, sizeof...(Types)> sprout::basic_string<typename std::decay<T>::type, 1 + sizeof...(Tail)>
> impl_type; > impl_type;
return impl_type::make(SPROUT_FORWARD(Types, args)...); return impl_type::make(SPROUT_FORWARD(Head, head), SPROUT_FORWARD(Tail, tail)...);
}
template<typename T, std::size_t N, typename Head, typename... Tail>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<T>::type, N>
make_string(Head&& head, Tail&&... tail) {
typedef sprout::detail::make_construct_impl<
sprout::basic_string<typename std::decay<T>::type, N>
> impl_type;
return impl_type::make(SPROUT_FORWARD(Head, head), SPROUT_FORWARD(Tail, tail)...);
}
template<sprout::detail::make_string_t = sprout::detail::make_string_in_head_type, typename Head, typename... Tail>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<Head>::type, 1 + sizeof...(Tail)>
make_string(Head&& head, Tail&&... tail) {
typedef sprout::detail::make_construct_impl<
sprout::basic_string<typename std::decay<Head>::type, 1 + sizeof...(Tail)>
> impl_type;
return impl_type::make(SPROUT_FORWARD(Head, head), SPROUT_FORWARD(Tail, tail)...);
}
template<std::size_t N, sprout::detail::make_string_t = sprout::detail::make_string_in_head_type, typename Head, typename... Tail>
inline SPROUT_CONSTEXPR sprout::basic_string<typename std::decay<Head>::type, N>
make_string(Head&& head, Tail&&... tail) {
typedef sprout::detail::make_construct_impl<
sprout::basic_string<typename std::decay<Head>::type, N>
> impl_type;
return impl_type::make(SPROUT_FORWARD(Head, head), SPROUT_FORWARD(Tail, tail)...);
} }
} // namespace sprout } // namespace sprout

View file

@ -50,7 +50,7 @@ namespace sprout {
typename Sequence::value_type, typename Sequence::value_type,
sprout::types::detail::str_length<Sequence>::value sprout::types::detail::str_length<Sequence>::value
> to_string_constant_impl(sprout::index_tuple<Indexes...>) { > to_string_constant_impl(sprout::index_tuple<Indexes...>) {
return sprout::make_string_as<typename Sequence::value_type>( return sprout::make_string<typename Sequence::value_type>(
sprout::types::tuple_element<Indexes, Sequence>::type::value... sprout::types::tuple_element<Indexes, Sequence>::type::value...
); );
} }

View file

@ -32,6 +32,13 @@ namespace sprout {
typedef sprout::detail::make_construct_impl<type> construct_type; typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(T(SPROUT_FORWARD(Types, args))...); return construct_type::make(T(SPROUT_FORWARD(Types, args))...);
} }
template<typename T, std::size_t N, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename std::remove_cv<T>::type, N>
make_valarray(Types&&... args) {
typedef sprout::valarray<typename std::remove_cv<T>::type, N> type;
typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(T(SPROUT_FORWARD(Types, args))...);
}
template<sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types> template<sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)> inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
make_valarray(Types&&... args) { make_valarray(Types&&... args) {
@ -40,6 +47,14 @@ namespace sprout {
typedef sprout::detail::make_construct_impl<type> construct_type; typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(value_type(SPROUT_FORWARD(Types, args))...); return construct_type::make(value_type(SPROUT_FORWARD(Types, args))...);
} }
template<std::size_t N, sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, N>
make_valarray(Types&&... args) {
typedef typename sprout::common_decay<Types...>::type value_type;
typedef sprout::valarray<value_type, N> type;
typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(value_type(SPROUT_FORWARD(Types, args))...);
}
// //
// make_valarray_without_narrowing // make_valarray_without_narrowing
@ -51,6 +66,13 @@ namespace sprout {
typedef sprout::detail::make_construct_impl<type> construct_type; typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(SPROUT_FORWARD(Types, args)...); return construct_type::make(SPROUT_FORWARD(Types, args)...);
} }
template<typename T, std::size_t N, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename std::remove_cv<T>::type, N>
make_valarray_without_narrowing(Types&&... args) {
typedef sprout::valarray<typename std::remove_cv<T>::type, N> type;
typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(SPROUT_FORWARD(Types, args)...);
}
template<sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types> template<sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)> inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
make_valarray_without_narrowing(Types&&... args) { make_valarray_without_narrowing(Types&&... args) {
@ -59,6 +81,14 @@ namespace sprout {
typedef sprout::detail::make_construct_impl<type> construct_type; typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(SPROUT_FORWARD(Types, args)...); return construct_type::make(SPROUT_FORWARD(Types, args)...);
} }
template<std::size_t N, sprout::detail::make_valarray_t = sprout::detail::make_valarray_in_common_elements, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, N>
make_valarray_without_narrowing(Types&&... args) {
typedef typename sprout::common_decay<Types...>::type value_type;
typedef sprout::valarray<value_type, N> type;
typedef sprout::detail::make_construct_impl<type> construct_type;
return construct_type::make(SPROUT_FORWARD(Types, args)...);
}
// //
// make_common_valarray // make_common_valarray
@ -68,6 +98,11 @@ namespace sprout {
make_common_valarray(Types&&... args) { make_common_valarray(Types&&... args) {
return sprout::make_valarray(SPROUT_FORWARD(Types, args)...); return sprout::make_valarray(SPROUT_FORWARD(Types, args)...);
} }
template<std::size_t N, typename... Types>
inline SPROUT_CONSTEXPR sprout::valarray<typename sprout::common_decay<Types...>::type, N>
make_common_valarray(Types&&... args) {
return sprout::make_valarray<N>(SPROUT_FORWARD(Types, args)...);
}
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_VALARRAY_MAKE_VALARRAY_HPP #endif // #ifndef SPROUT_VALARRAY_MAKE_VALARRAY_HPP

View file

@ -5,8 +5,8 @@
Distributed under the Boost Software License, Version 1.0. (See accompanying 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) file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/ =============================================================================*/
#ifndef SPROUT_VALARRAY_MASKE_ARRAY_HPP #ifndef SPROUT_VALARRAY_MASK_ARRAY_HPP
#define SPROUT_VALARRAY_MASKE_ARRAY_HPP #define SPROUT_VALARRAY_MASK_ARRAY_HPP
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp> #include <sprout/workaround/std/cstddef.hpp>
@ -231,4 +231,4 @@ namespace sprout {
} }
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_VALARRAY_MASKE_ARRAY_HPP #endif // #ifndef SPROUT_VALARRAY_MASK_ARRAY_HPP