fix make_array (add common type version)

This commit is contained in:
bolero-MURAKAMI 2014-04-15 12:31:13 +09:00
parent d082fa743b
commit 6f399977b2
2 changed files with 16 additions and 16 deletions

View file

@ -19,7 +19,7 @@ namespace testspr {
SPROUT_STATIC_CONSTEXPR int carr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
SPROUT_STATIC_CONSTEXPR auto arr1 = sprout::to_array(carr);
SPROUT_STATIC_CONSTEXPR auto arr2 = sprout::make_array<int>(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
SPROUT_STATIC_CONSTEXPR auto arr3 = sprout::make_common_array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
SPROUT_STATIC_CONSTEXPR auto arr3 = sprout::make_array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
TESTSPR_BOTH_ASSERT(testspr::equal(carr, arr1));
TESTSPR_BOTH_ASSERT(testspr::equal(carr, arr2));

View file

@ -17,6 +17,11 @@
#include <sprout/type_traits/common_decay.hpp>
namespace sprout {
namespace detail {
enum make_array_t {
make_array_in_common_elements
};
} // namespace detail
//
// make_array
//
@ -25,16 +30,15 @@ namespace sprout {
make_array(Types&&... args) {
return sprout::array<typename std::remove_cv<T>::type, sizeof...(Types)>{{T(SPROUT_FORWARD(Types, args))...}};
}
// !!! OLD:
// template<typename... Types>
// inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
// make_array(Types&&... args) {
// typedef sprout::array<
// typename sprout::common_decay<Types...>::type,
// sizeof...(Types)
// > type;
// return type{{typename sprout::common_decay<Types...>::type(SPROUT_FORWARD(Types, args))...}};
// }
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)>
make_array(Types&&... args) {
typedef sprout::array<
typename sprout::common_decay<Types...>::type,
sizeof...(Types)
> type;
return type{{typename sprout::common_decay<Types...>::type(SPROUT_FORWARD(Types, args))...}};
}
//
// make_common_array
@ -42,11 +46,7 @@ namespace sprout {
template<typename... Types>
inline SPROUT_CONSTEXPR sprout::array<typename sprout::common_decay<Types...>::type, sizeof...(Types)>
make_common_array(Types&&... args) {
typedef sprout::array<
typename sprout::common_decay<Types...>::type,
sizeof...(Types)
> type;
return type{{typename sprout::common_decay<Types...>::type(SPROUT_FORWARD(Types, args))...}};
return sprout::make_array(SPROUT_FORWARD(Types, args)...);
}
//