diff --git a/libs/tuple/test/tuple.cpp b/libs/tuple/test/tuple.cpp index 192677de..0c8d9baf 100644 --- a/libs/tuple/test/tuple.cpp +++ b/libs/tuple/test/tuple.cpp @@ -10,6 +10,7 @@ #include #include +#include #include namespace testspr { @@ -92,6 +93,18 @@ namespace testspr { TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); } + { + auto tup3 = tup2; + tup3 = sprout::pair(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(1l, 1.0f); + TESTSPR_ASSERT(sprout::tuples::get<0>(tup3) == 1); + TESTSPR_ASSERT(sprout::tuples::get<1>(tup3) == 1.0); + } // swap { diff --git a/sprout/cstdlib/str_to_float.hpp b/sprout/cstdlib/str_to_float.hpp index d1ed165a..07f4c422 100644 --- a/sprout/cstdlib/str_to_float.hpp +++ b/sprout/cstdlib/str_to_float.hpp @@ -241,15 +241,13 @@ namespace sprout { inline SPROUT_CONSTEXPR FloatType str_to_float(CStrIterator str, CharPtr* endptr) { return !endptr ? sprout::detail::str_to_float(str) -#ifdef __MINGW32__ - : std::is_same::type, float>::value ? strtof(&*str, endptr) +#if defined(__MINGW32__) + : std::is_same::type, float>::value ? ::strtof(&*str, endptr) + : std::is_same::type, double>::value ? std::strtod(&*str, endptr) + : ::strtold(&*str, endptr) #else : std::is_same::type, float>::value ? std::strtof(&*str, endptr) -#endif : std::is_same::type, double>::value ? std::strtod(&*str, endptr) -#ifdef __MINGW32__ - : strtold(&*str, endptr) -#else : std::strtold(&*str, endptr) #endif ; diff --git a/sprout/cstdlib/str_to_int.hpp b/sprout/cstdlib/str_to_int.hpp index 4c2893f8..3b8db4f5 100644 --- a/sprout/cstdlib/str_to_int.hpp +++ b/sprout/cstdlib/str_to_int.hpp @@ -99,31 +99,29 @@ namespace sprout { template inline SPROUT_CONSTEXPR IntType str_to_int(CStrIterator str, CharPtr* endptr, int base) { -#if defined(_MSC_VER) return !endptr ? sprout::detail::str_to_int(str, base) +#if defined(_MSC_VER) : std::is_signed::value ? static_cast(std::strtol(&*str, endptr, base)) : static_cast(std::strtoul(&*str, endptr, base)) - ; -#else - return !endptr ? sprout::detail::str_to_int(str, base) +#elif defined(__MINGW32__) : std::is_signed::value ? sizeof(IntType) <= sizeof(long) ? static_cast(std::strtol(&*str, endptr, base)) -#ifdef __MINGW32__ - : sizeof(IntType) <= sizeof(long long) ? static_cast(strtoll(&*str, endptr, base)) -#else - : sizeof(IntType) <= sizeof(long long) ? static_cast(std::strtoll(&*str, endptr, base)) -#endif + : sizeof(IntType) <= sizeof(long long) ? static_cast(::strtoll(&*str, endptr, base)) : static_cast(std::strtoimax(&*str, endptr, base)) : sizeof(IntType) <= sizeof(unsigned long) ? static_cast(std::strtoul(&*str, endptr, base)) -#ifdef __MINGW32__ - : sizeof(IntType) <= sizeof(unsigned long long) ? static_cast(strtoull(&*str, endptr, base)) -#else - : sizeof(IntType) <= sizeof(unsigned long long) ? static_cast(std::strtoull(&*str, endptr, base)) -#endif + : sizeof(IntType) <= sizeof(unsigned long long) ? static_cast(::strtoull(&*str, endptr, base)) + : static_cast(std::strtoumax(&*str, endptr, base)) +#else + : std::is_signed::value + ? sizeof(IntType) <= sizeof(long) ? static_cast(std::strtol(&*str, endptr, base)) + : sizeof(IntType) <= sizeof(long long) ? static_cast(std::strtoll(&*str, endptr, base)) + : static_cast(std::strtoimax(&*str, endptr, base)) + : sizeof(IntType) <= sizeof(unsigned long) ? static_cast(std::strtoul(&*str, endptr, base)) + : sizeof(IntType) <= sizeof(unsigned long long) ? static_cast(std::strtoull(&*str, endptr, base)) : static_cast(std::strtoumax(&*str, endptr, base)) - ; #endif + ; } } // namespace detail diff --git a/sprout/static_assert.hpp b/sprout/static_assert.hpp new file mode 100644 index 00000000..17ee7ece --- /dev/null +++ b/sprout/static_assert.hpp @@ -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 +#include + +// +// 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 diff --git a/sprout/static_warning.hpp b/sprout/static_warning.hpp new file mode 100644 index 00000000..6da4f6ef --- /dev/null +++ b/sprout/static_warning.hpp @@ -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 + +namespace sprout { + // + // static_warning + // + template + struct static_warning; + template<> + struct static_warning { + template + static void warn() {} + }; + template <> + struct static_warning { + template + 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(); \ + } \ + } +#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 diff --git a/sprout/string/to_string_value.hpp b/sprout/string/to_string_value.hpp index bde1b6d4..aac08ce2 100644 --- a/sprout/string/to_string_value.hpp +++ b/sprout/string/to_string_value.hpp @@ -16,9 +16,8 @@ namespace sprout { // // to_string_value - // [[deprecated]] // - struct SPROUT_DEPRECATED to_string_value { + struct to_string_value { public: template SPROUT_CONSTEXPR decltype(sprout::to_string(std::declval())) diff --git a/sprout/tuple/tuple/tuple.hpp b/sprout/tuple/tuple/tuple.hpp index 7e08771e..b4f4c685 100644 --- a/sprout/tuple/tuple/tuple.hpp +++ b/sprout/tuple/tuple/tuple.hpp @@ -53,6 +53,29 @@ namespace sprout { inline SPROUT_CONSTEXPR sprout::tuples::tuple::tuple(sprout::tuples::flexibly_construct_t, sprout::pair&& t) : impl_type(SPROUT_FORWARD(UType1, t.first), SPROUT_FORWARD(UType2, t.second)) {} + // tuple assignment + template + template< + typename UType1, typename UType2, + typename + > + inline SPROUT_CXX14_CONSTEXPR sprout::tuples::tuple& + sprout::tuples::tuple::operator=(sprout::pair 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 + template< + typename UType1, typename UType2, + typename + > + inline SPROUT_CXX14_CONSTEXPR sprout::tuples::tuple& + sprout::tuples::tuple::operator=(sprout::pair&& 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 sprout diff --git a/sprout/tuple/tuple/tuple_decl.hpp b/sprout/tuple/tuple/tuple_decl.hpp index 56ba143d..fe710ce7 100644 --- a/sprout/tuple/tuple/tuple_decl.hpp +++ b/sprout/tuple/tuple/tuple_decl.hpp @@ -272,6 +272,18 @@ namespace sprout { >... > {}; + + template + struct is_flexibly_assignable_impl; + template + struct is_flexibly_assignable_impl, Utypes...> + : public sprout::tpp::all_of< + std::is_assignable< + typename sprout::pack_element::type, + typename sprout::pack_element::type + >... + > + {}; public: template struct is_flexibly_convert_constructible @@ -304,6 +316,38 @@ namespace sprout { struct is_clvref_fixedly_convert_constructible : public is_fixedly_convert_constructible {}; + + template + 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 + struct is_rvref_flexibly_assignable + : public is_flexibly_assignable + {}; + template + struct is_clvref_flexibly_assignable + : public is_flexibly_assignable + {}; + + template + struct is_fixedly_assignable + : public sprout::integral_constant< + bool, + (sizeof...(UTypes) == sizeof...(Types) && is_flexibly_assignable::value) + > + {}; + template + struct is_rvref_fixedly_assignable + : public is_fixedly_assignable + {}; + template + struct is_clvref_fixedly_assignable + : public is_fixedly_assignable + {}; public: // tuple construction SPROUT_CONSTEXPR tuple() @@ -428,6 +472,20 @@ namespace sprout { static_cast(*this) = sprout::move(rhs); return *this; } + template< + typename UType1, typename UType2, + typename = typename std::enable_if< + is_clvref_fixedly_assignable::value + >::type + > + SPROUT_CXX14_CONSTEXPR tuple& operator=(sprout::pair const& rhs); + template< + typename UType1, typename UType2, + typename = typename std::enable_if< + is_rvref_fixedly_assignable::value + >::type + > + SPROUT_CXX14_CONSTEXPR tuple& operator=(sprout::pair&& rhs); // tuple swap SPROUT_CXX14_CONSTEXPR void swap(tuple& other) SPROUT_NOEXCEPT_EXPR(sprout::tpp::all_of_c(), std::declval()), false)...>::value) diff --git a/sprout/type.hpp b/sprout/type.hpp index de17def8..842ba5c9 100644 --- a/sprout/type.hpp +++ b/sprout/type.hpp @@ -18,5 +18,6 @@ #include #include #include +#include #endif // #ifndef SPROUT_TYPE_HPP diff --git a/sprout/type/print.hpp b/sprout/type/print.hpp new file mode 100644 index 00000000..ba6cdb0a --- /dev/null +++ b/sprout/type/print.hpp @@ -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 +#include + +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 + struct dependent_unsigned { + static unsigned const value = 1; + }; +#endif + } // namespace detail + + // + // print + // + template + struct print + : public sprout::identity +#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::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 diff --git a/testspr/assert.hpp b/testspr/assert.hpp index f24d9dbd..d4d38ce8 100644 --- a/testspr/assert.hpp +++ b/testspr/assert.hpp @@ -10,10 +10,10 @@ #include #include -#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING -# include -#endif #include +#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING +# include +#endif namespace testspr { //