add tuple assignment for pair

This commit is contained in:
bolero-MURAKAMI 2014-03-01 10:35:24 +09:00
parent ae9578ce37
commit 87ed3d5548
11 changed files with 262 additions and 26 deletions

View file

@ -10,6 +10,7 @@
#include <sstream> #include <sstream>
#include <sprout/tuple/tuple.hpp> #include <sprout/tuple/tuple.hpp>
#include <sprout/utility/pair.hpp>
#include <testspr/tools.hpp> #include <testspr/tools.hpp>
namespace testspr { namespace testspr {
@ -92,6 +93,18 @@ namespace testspr {
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
} }
{
auto tup3 = tup2;
tup3 = sprout::pair<int, double>(1, 1.0);
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
}
{
auto tup3 = tup2;
tup3 = sprout::pair<long, float>(1l, 1.0f);
TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1);
TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0);
}
// swap // swap
{ {

View file

@ -241,15 +241,13 @@ namespace sprout {
inline SPROUT_CONSTEXPR FloatType inline SPROUT_CONSTEXPR FloatType
str_to_float(CStrIterator str, CharPtr* endptr) { str_to_float(CStrIterator str, CharPtr* endptr) {
return !endptr ? sprout::detail::str_to_float<FloatType>(str) return !endptr ? sprout::detail::str_to_float<FloatType>(str)
#ifdef __MINGW32__ #if defined(__MINGW32__)
: std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? strtof(&*str, endptr) : std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? ::strtof(&*str, endptr)
: std::is_same<typename std::remove_cv<FloatType>::type, double>::value ? std::strtod(&*str, endptr)
: ::strtold(&*str, endptr)
#else #else
: std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? std::strtof(&*str, endptr) : std::is_same<typename std::remove_cv<FloatType>::type, float>::value ? std::strtof(&*str, endptr)
#endif
: std::is_same<typename std::remove_cv<FloatType>::type, double>::value ? std::strtod(&*str, endptr) : std::is_same<typename std::remove_cv<FloatType>::type, double>::value ? std::strtod(&*str, endptr)
#ifdef __MINGW32__
: strtold(&*str, endptr)
#else
: std::strtold(&*str, endptr) : std::strtold(&*str, endptr)
#endif #endif
; ;

View file

@ -99,31 +99,29 @@ namespace sprout {
template<typename IntType, typename CStrIterator, typename CharPtr> template<typename IntType, typename CStrIterator, typename CharPtr>
inline SPROUT_CONSTEXPR IntType inline SPROUT_CONSTEXPR IntType
str_to_int(CStrIterator str, CharPtr* endptr, int base) { str_to_int(CStrIterator str, CharPtr* endptr, int base) {
#if defined(_MSC_VER)
return !endptr ? sprout::detail::str_to_int<IntType>(str, base) return !endptr ? sprout::detail::str_to_int<IntType>(str, base)
#if defined(_MSC_VER)
: std::is_signed<IntType>::value : std::is_signed<IntType>::value
? static_cast<IntType>(std::strtol(&*str, endptr, base)) ? static_cast<IntType>(std::strtol(&*str, endptr, base))
: static_cast<IntType>(std::strtoul(&*str, endptr, base)) : static_cast<IntType>(std::strtoul(&*str, endptr, base))
; #elif defined(__MINGW32__)
#else
return !endptr ? sprout::detail::str_to_int<IntType>(str, base)
: std::is_signed<IntType>::value : std::is_signed<IntType>::value
? sizeof(IntType) <= sizeof(long) ? static_cast<IntType>(std::strtol(&*str, endptr, base)) ? sizeof(IntType) <= sizeof(long) ? static_cast<IntType>(std::strtol(&*str, endptr, base))
#ifdef __MINGW32__ : sizeof(IntType) <= sizeof(long long) ? static_cast<IntType>(::strtoll(&*str, endptr, base))
: sizeof(IntType) <= sizeof(long long) ? static_cast<IntType>(strtoll(&*str, endptr, base))
#else
: sizeof(IntType) <= sizeof(long long) ? static_cast<IntType>(std::strtoll(&*str, endptr, base))
#endif
: static_cast<IntType>(std::strtoimax(&*str, endptr, base)) : static_cast<IntType>(std::strtoimax(&*str, endptr, base))
: sizeof(IntType) <= sizeof(unsigned long) ? static_cast<IntType>(std::strtoul(&*str, endptr, base)) : sizeof(IntType) <= sizeof(unsigned long) ? static_cast<IntType>(std::strtoul(&*str, endptr, base))
#ifdef __MINGW32__ : sizeof(IntType) <= sizeof(unsigned long long) ? static_cast<IntType>(::strtoull(&*str, endptr, base))
: sizeof(IntType) <= sizeof(unsigned long long) ? static_cast<IntType>(strtoull(&*str, endptr, base)) : static_cast<IntType>(std::strtoumax(&*str, endptr, base))
#else #else
: sizeof(IntType) <= sizeof(unsigned long long) ? static_cast<IntType>(std::strtoull(&*str, endptr, base)) : std::is_signed<IntType>::value
#endif ? sizeof(IntType) <= sizeof(long) ? static_cast<IntType>(std::strtol(&*str, endptr, base))
: sizeof(IntType) <= sizeof(long long) ? static_cast<IntType>(std::strtoll(&*str, endptr, base))
: static_cast<IntType>(std::strtoimax(&*str, endptr, base))
: sizeof(IntType) <= sizeof(unsigned long) ? static_cast<IntType>(std::strtoul(&*str, endptr, base))
: sizeof(IntType) <= sizeof(unsigned long long) ? static_cast<IntType>(std::strtoull(&*str, endptr, base))
: static_cast<IntType>(std::strtoumax(&*str, endptr, base)) : static_cast<IntType>(std::strtoumax(&*str, endptr, base))
;
#endif #endif
;
} }
} // namespace detail } // namespace detail

26
sprout/static_assert.hpp Normal file
View file

@ -0,0 +1,26 @@
/*=============================================================================
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_STATIC_ASSERT_HPP
#define SPROUT_STATIC_ASSERT_HPP
#include <sprout/config.hpp>
#include <sprout/preprocessor/stringize.hpp>
//
// SPROUT_STATIC_ASSERT_MSG
// SPROUT_STATIC_ASSERT
// SPROUT_STATIC_ASSERT_PREPROCESSED
//
#define SPROUT_STATIC_ASSERT_MSG(COND, MESSAGE) \
static_assert(COND, MESSAGE)
#define SPROUT_STATIC_ASSERT(COND) \
SPROUT_STATIC_ASSERT_MSG(COND, #COND)
#define SPROUT_STATIC_ASSERT_PREPROCESSED(COND) \
SPROUT_STATIC_ASSERT_MSG(COND, #COND " \n[[preprocessed]]: " SPROUT_PP_STRINGIZE(COND))
#endif // #ifndef SPROUT_STATIC_ASSERT_HPP

49
sprout/static_warning.hpp Normal file
View file

@ -0,0 +1,49 @@
/*=============================================================================
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_STATIC_WARNING_HPP
#define SPROUT_STATIC_WARNING_HPP
#include <sprout/config.hpp>
namespace sprout {
//
// static_warning
//
template<bool C>
struct static_warning;
template<>
struct static_warning<true> {
template<typename Message>
static void warn() {}
};
template <>
struct static_warning<false> {
template<typename Message>
static void warn() {
Message static_warning_failed;
}
};
} // namespace sprout
//
// SPROUT_STATIC_WARNING
//
#define SPROUT_STATIC_WARNING_IMPL_2(cond, msg, line) \
struct sprout_static_warning_line_ ## line { \
struct msg {}; \
sprout_static_warning_line_ ## line() { \
::sprout::static_warning<(cond)>:: \
warn<void***** (msg::*****)()>(); \
} \
}
#define SPROUT_STATIC_WARNING_IMPL(cond, msg) \
SPROUT_STATIC_WARNING_IMPL_2(cond, msg, __LINE__)
#define SPROUT_STATIC_WARNING(cond) \
SPROUT_STATIC_WARNING_IMPL(cond, static_warning_failed)
#endif // #ifndef SPROUT_STATIC_WARNING_HPP

View file

@ -16,9 +16,8 @@
namespace sprout { namespace sprout {
// //
// to_string_value // to_string_value
// [[deprecated]]
// //
struct SPROUT_DEPRECATED to_string_value { struct to_string_value {
public: public:
template<typename T> template<typename T>
SPROUT_CONSTEXPR decltype(sprout::to_string(std::declval<T>())) SPROUT_CONSTEXPR decltype(sprout::to_string(std::declval<T>()))

View file

@ -53,6 +53,29 @@ namespace sprout {
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UType1, UType2>&& t) inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UType1, UType2>&& t)
: impl_type(SPROUT_FORWARD(UType1, t.first), SPROUT_FORWARD(UType2, t.second)) : impl_type(SPROUT_FORWARD(UType1, t.first), SPROUT_FORWARD(UType2, t.second))
{} {}
// tuple assignment
template<typename... Types>
template<
typename UType1, typename UType2,
typename
>
inline SPROUT_CXX14_CONSTEXPR sprout::tuples::tuple<Types...>&
sprout::tuples::tuple<Types...>::operator=(sprout::pair<UType1, UType2> const& rhs) {
sprout::tuples::detail::tuple_impl<0, Types...>::head(*this) = rhs.first;
sprout::tuples::detail::tuple_impl<1, Types...>::head(*this) = rhs.second;
return *this;
}
template<typename... Types>
template<
typename UType1, typename UType2,
typename
>
inline SPROUT_CXX14_CONSTEXPR sprout::tuples::tuple<Types...>&
sprout::tuples::tuple<Types...>::operator=(sprout::pair<UType1, UType2>&& rhs) {
sprout::tuples::detail::tuple_impl<0, Types...>::head(*this) = sprout::move(rhs.first);
sprout::tuples::detail::tuple_impl<1, Types...>::head(*this) = sprout::move(rhs.second);
return *this;
}
} // namespace tuples } // namespace tuples
} // namespace sprout } // namespace sprout

View file

@ -272,6 +272,18 @@ namespace sprout {
>... >...
> >
{}; {};
template<typename TndexTuple, typename... Utypes>
struct is_flexibly_assignable_impl;
template<sprout::index_t... Indexes, typename... Utypes>
struct is_flexibly_assignable_impl<sprout::index_tuple<Indexes...>, Utypes...>
: public sprout::tpp::all_of<
std::is_assignable<
typename sprout::pack_element<Indexes, Types...>::type,
typename sprout::pack_element<Indexes, Utypes...>::type
>...
>
{};
public: public:
template<typename... UTypes> template<typename... UTypes>
struct is_flexibly_convert_constructible struct is_flexibly_convert_constructible
@ -304,6 +316,38 @@ namespace sprout {
struct is_clvref_fixedly_convert_constructible struct is_clvref_fixedly_convert_constructible
: public is_fixedly_convert_constructible<UTypes const&...> : public is_fixedly_convert_constructible<UTypes const&...>
{}; {};
template<typename... UTypes>
struct is_flexibly_assignable
: public is_flexibly_assignable_impl<
typename sprout::make_index_tuple<(sizeof...(UTypes) < sizeof...(Types) ? sizeof...(UTypes) : sizeof...(Types))>::type,
UTypes...
>
{};
template<typename... UTypes>
struct is_rvref_flexibly_assignable
: public is_flexibly_assignable<UTypes&&...>
{};
template<typename... UTypes>
struct is_clvref_flexibly_assignable
: public is_flexibly_assignable<UTypes const&...>
{};
template<typename... UTypes>
struct is_fixedly_assignable
: public sprout::integral_constant<
bool,
(sizeof...(UTypes) == sizeof...(Types) && is_flexibly_assignable<UTypes...>::value)
>
{};
template<typename... UTypes>
struct is_rvref_fixedly_assignable
: public is_fixedly_assignable<UTypes&&...>
{};
template<typename... UTypes>
struct is_clvref_fixedly_assignable
: public is_fixedly_assignable<UTypes const&...>
{};
public: public:
// tuple construction // tuple construction
SPROUT_CONSTEXPR tuple() SPROUT_CONSTEXPR tuple()
@ -428,6 +472,20 @@ namespace sprout {
static_cast<impl_type&>(*this) = sprout::move(rhs); static_cast<impl_type&>(*this) = sprout::move(rhs);
return *this; return *this;
} }
template<
typename UType1, typename UType2,
typename = typename std::enable_if<
is_clvref_fixedly_assignable<UType1, UType2>::value
>::type
>
SPROUT_CXX14_CONSTEXPR tuple& operator=(sprout::pair<UType1, UType2> const& rhs);
template<
typename UType1, typename UType2,
typename = typename std::enable_if<
is_rvref_fixedly_assignable<UType1, UType2>::value
>::type
>
SPROUT_CXX14_CONSTEXPR tuple& operator=(sprout::pair<UType1, UType2>&& rhs);
// tuple swap // tuple swap
SPROUT_CXX14_CONSTEXPR void swap(tuple& other) SPROUT_CXX14_CONSTEXPR void swap(tuple& other)
SPROUT_NOEXCEPT_EXPR(sprout::tpp::all_of_c<SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::swap(std::declval<Types&>(), std::declval<Types&>()), false)...>::value) SPROUT_NOEXCEPT_EXPR(sprout::tpp::all_of_c<SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::swap(std::declval<Types&>(), std::declval<Types&>()), false)...>::value)

View file

@ -18,5 +18,6 @@
#include <sprout/type/functional.hpp> #include <sprout/type/functional.hpp>
#include <sprout/type/algorithm.hpp> #include <sprout/type/algorithm.hpp>
#include <sprout/type/operation.hpp> #include <sprout/type/operation.hpp>
#include <sprout/type/print.hpp>
#endif // #ifndef SPROUT_TYPE_HPP #endif // #ifndef SPROUT_TYPE_HPP

71
sprout/type/print.hpp Normal file
View file

@ -0,0 +1,71 @@
/*=============================================================================
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_PRINT_HPP
#define SPROUT_TYPE_PRINT_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout {
namespace types {
namespace detail {
#if defined(_MSC_VER)
# pragma warning(push, 3)
# pragma warning(disable: 4307)
#elif defined(__MWERKS__)
# pragma warn_hidevirtual on
struct print_base {
virtual void f() {}
};
#endif
#if defined(__EDG_VERSION__)
template<typename T>
struct dependent_unsigned {
static unsigned const value = 1;
};
#endif
} // namespace detail
//
// print
//
template<typename T>
struct print
: public sprout::identity<T>
#if defined(__MWERKS__)
, public sprout::types::detail::print_base
#endif
{
#if defined(_MSC_VER)
enum {
n = sizeof(T) + -1
};
#elif defined(__MWERKS__)
void f(int);
#else
enum {
n =
# if defined(__EDG_VERSION__)
sprout::types::detail::dependent_unsigned<T>::value > -1
# else
sizeof(T) > -1
# endif
};
#endif
};
#if defined(_MSC_VER)
# pragma warning(pop)
#elif defined(__MWERKS__)
# pragma warn_hidevirtual reset
#endif
} // namespace types
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_PRINT_HPP

View file

@ -10,10 +10,10 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING
# include <boost/serialization/static_warning.hpp>
#endif
#include <sprout/assert.hpp> #include <sprout/assert.hpp>
#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING
# include <sprout/static_warning.hpp>
#endif
namespace testspr { namespace testspr {
// //