From ff3a85cf55f9962b28ea27229d032a7dcb6bd34f Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 22 Oct 2014 10:04:41 +0900 Subject: [PATCH] add packer [n4144] --- sprout/ctime.hpp | 15 ++++ sprout/ctime/difftime.hpp | 24 +++++++ sprout/ctime/to_time_t.hpp | 111 +++++++++++++++++++++++++++++ sprout/type.hpp | 1 + sprout/type/packer.hpp | 139 +++++++++++++++++++++++++++++++++++++ sprout/type/type_tuple.hpp | 2 + testspr/header_all.hpp | 1 + 7 files changed, 293 insertions(+) create mode 100644 sprout/ctime.hpp create mode 100644 sprout/ctime/difftime.hpp create mode 100644 sprout/ctime/to_time_t.hpp create mode 100644 sprout/type/packer.hpp diff --git a/sprout/ctime.hpp b/sprout/ctime.hpp new file mode 100644 index 00000000..652b40f8 --- /dev/null +++ b/sprout/ctime.hpp @@ -0,0 +1,15 @@ +/*============================================================================= + 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_CTIME_HPP +#define SPROUT_CTIME_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_CTIME_HPP diff --git a/sprout/ctime/difftime.hpp b/sprout/ctime/difftime.hpp new file mode 100644 index 00000000..472f2752 --- /dev/null +++ b/sprout/ctime/difftime.hpp @@ -0,0 +1,24 @@ +/*============================================================================= + 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_CTIME_DIFFTIME_HPP +#define SPROUT_CTIME_DIFFTIME_HPP + +#include +#include + +namespace sprout { + // + // 7.23.2.2 The difftime function + // + inline SPROUT_CONSTEXPR double + difftime(std::time_t time1, std::time_t time0) { + return static_cast(time1) - static_cast(time0); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CTIME_DIFFTIME_HPP diff --git a/sprout/ctime/to_time_t.hpp b/sprout/ctime/to_time_t.hpp new file mode 100644 index 00000000..df9ec6f8 --- /dev/null +++ b/sprout/ctime/to_time_t.hpp @@ -0,0 +1,111 @@ +/*============================================================================= + 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_CTIME_TO_TIME_T_HPP +#define SPROUT_CTIME_TO_TIME_T_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace detail { + inline SPROUT_CONSTEXPR std::time_t + to_time_t_impl(int year, int mon, int day, int hour, int min, int sec) { + return ((( + std::time_t(year / 4 - year / 100 + year / 400 + 367 * mon / 12 + day) + year * 365 - 719499 + ) * 24 + hour + ) * 60 + min + ) * 60 + sec + ; + } + } // namespace detail + // + // to_time_t + // + inline SPROUT_CONSTEXPR std::time_t + to_time_t(int year, int mon, int day, int hour, int min, int sec) { + return mon <= 2 + ? sprout::detail::to_time_t_impl(year - 1, mon + 10, day, hour, min, sec) + : sprout::detail::to_time_t_impl(year, mon - 2, day, hour, min, sec) + ; + } + inline SPROUT_CONSTEXPR std::time_t + to_time_t(std::tm const& t) { + return sprout::to_time_t(t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); + } + + namespace detail { + template + inline SPROUT_CONSTEXPR int + get_num(Elem e) { + return !sprout::isdigit(e) ? 0 + : e - static_cast('0') + ; + } + template + inline SPROUT_CONSTEXPR int + get_month(InputIterator const& date) { + return sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Jan")) ? 1 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Feb")) ? 2 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Mar")) ? 3 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Apr")) ? 4 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("May")) ? 5 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Jun")) ? 6 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Jul")) ? 7 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Aug")) ? 8 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Sep")) ? 9 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Oct")) ? 10 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Nov")) ? 11 + : sprout::equal(sprout::ptr_index(date), sprout::ptr_index(date, 3), sprout::ptr_index("Dec")) ? 12 + : 0 + ; + } + template + inline SPROUT_CONSTEXPR int + get_day(RandomAccessIterator const& date) { + return sprout::detail::get_num(date[0]) * 10 + + sprout::detail::get_num(date[1]) + ; + } + template + inline SPROUT_CONSTEXPR int + get_year(RandomAccessIterator const& date) { + return sprout::detail::get_num(date[0]) * 1000 + + sprout::detail::get_num(date[1]) * 100 + + sprout::detail::get_num(date[2]) * 10 + + sprout::detail::get_num(date[3]) + ; + } + template + inline SPROUT_CONSTEXPR int + get_time(RandomAccessIterator const& time) { + return sprout::detail::get_num(time[0]) * 10 + + sprout::detail::get_num(time[1]) + ; + } + } // namespace detail + // + // to_time_t + // + template + inline SPROUT_CONSTEXPR std::time_t + to_time_t(RandomAccessIterator1 const& date, RandomAccessIterator2 const& time) { + return sprout::to_time_t( + sprout::detail::get_year(date + 7), + sprout::detail::get_month(date + 0), + sprout::detail::get_day(date + 4), + sprout::detail::get_time(time + 0), + sprout::detail::get_time(time + 3), + sprout::detail::get_time(time + 6) + ); + } +} // namespace sprout + +#endif // #ifndef SPROUT_CTIME_TO_TIME_T_HPP diff --git a/sprout/type.hpp b/sprout/type.hpp index d0437103..2340f16a 100644 --- a/sprout/type.hpp +++ b/sprout/type.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/sprout/type/packer.hpp b/sprout/type/packer.hpp new file mode 100644 index 00000000..7cd9c175 --- /dev/null +++ b/sprout/type/packer.hpp @@ -0,0 +1,139 @@ +/*============================================================================= + 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_PACKER_HPP +#define SPROUT_TYPE_PACKER_HPP + +#include +#include +#include +#include + +namespace sprout { + namespace types { + // + // packer + // +#if SPROUT_USE_TEMPLATE_ALIASES + template + using packer = sprout::types::type_tuple; +#else // #if SPROUT_USE_TEMPLATE_ALIASES + template + struct packer + : public sprout::types::type_tuple + {}; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + } // namespace types + + using sprout::types::packer; +} // namespace sprout + +#if !SPROUT_USE_TEMPLATE_ALIASES + +namespace std { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmismatched-tags" +#endif + // + // tuple_size + // + template + struct tuple_size > + : public std::tuple_size > + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public sprout::types::tuple_element > + {}; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +} // namespace std + +namespace sprout { + // + // tuple_get + // + template + inline SPROUT_CONSTEXPR typename std::tuple_element >::type + tuple_get(sprout::types::packer) SPROUT_NOEXCEPT { + static_assert(I < sizeof...(Values), "tuple_get: index out of range"); + typedef typename std::tuple_element >::type type; + return type(); + } +} // namespace sprout + +#endif // #if !SPROUT_USE_TEMPLATE_ALIASES + +#include +#include +#include + +namespace sprout { + namespace types { + // + // is_contained_in + // + template + struct is_contained_in + : public sprout::types::contains, T> + {}; + + // + // contains_types + // + namespace detail { + template + struct contains_types_impl; + template + struct contains_types_impl > + : public sprout::tpp::all_of::type, T>...> + {}; + } // namespace detail + template + struct contains_types + : public sprout::types::detail::contains_types_impl::value>::type> + {}; + +#if SPROUT_USE_TEMPLATE_ALIASES + template + using is_contained_in_t = typename sprout::types::is_contained_in::type; + + template + using contains_types_t = typename sprout::types::contains_types::type; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + template + SPROUT_STATIC_CONSTEXPR bool is_contained_in_v = sprout::types::is_contained_in::value; + + template + SPROUT_STATIC_CONSTEXPR bool contains_types_v = sprout::types::contains_types::value; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES + + } // namespace types + + using sprout::types::is_contained_in; + using sprout::types::contains_types; + +#if SPROUT_USE_TEMPLATE_ALIASES + using sprout::types::is_contained_in_t; + using sprout::types::contains_types_t; +#endif // #if SPROUT_USE_TEMPLATE_ALIASES + +#if SPROUT_USE_VARIABLE_TEMPLATES + using sprout::types::is_contained_in_v; + using sprout::types::contains_types_v; +#endif // #if SPROUT_USE_VARIABLE_TEMPLATES +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_PACKER_HPP diff --git a/sprout/type/type_tuple.hpp b/sprout/type/type_tuple.hpp index 6680051c..2f6d7854 100644 --- a/sprout/type/type_tuple.hpp +++ b/sprout/type/type_tuple.hpp @@ -37,6 +37,8 @@ namespace sprout { template SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::types::type_tuple::static_size; } // namespace types + + using sprout::types::type_tuple; } // namespace sprout #endif // #ifndef SPROUT_TYPE_TYPE_TUPLE_HPP diff --git a/testspr/header_all.hpp b/testspr/header_all.hpp index 83a20f72..a5d3b17d 100644 --- a/testspr/header_all.hpp +++ b/testspr/header_all.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include