mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-11-25 00:43:44 +00:00
add packer [n4144]
This commit is contained in:
parent
bba5813733
commit
ff3a85cf55
7 changed files with 293 additions and 0 deletions
15
sprout/ctime.hpp
Normal file
15
sprout/ctime.hpp
Normal file
|
@ -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 <sprout/config.hpp>
|
||||||
|
#include <sprout/ctime/difftime.hpp>
|
||||||
|
#include <sprout/ctime/to_time_t.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_CTIME_HPP
|
24
sprout/ctime/difftime.hpp
Normal file
24
sprout/ctime/difftime.hpp
Normal file
|
@ -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 <ctime>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
|
||||||
|
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<double>(time1) - static_cast<double>(time0);
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_CTIME_DIFFTIME_HPP
|
111
sprout/ctime/to_time_t.hpp
Normal file
111
sprout/ctime/to_time_t.hpp
Normal file
|
@ -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 <ctime>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/ctype/ascii.hpp>
|
||||||
|
#include <sprout/algorithm/equal.hpp>
|
||||||
|
#include <sprout/iterator/ptr_index_iterator.hpp>
|
||||||
|
|
||||||
|
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<typename Elem>
|
||||||
|
inline SPROUT_CONSTEXPR int
|
||||||
|
get_num(Elem e) {
|
||||||
|
return !sprout::isdigit(e) ? 0
|
||||||
|
: e - static_cast<Elem>('0')
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<typename InputIterator>
|
||||||
|
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<typename RandomAccessIterator>
|
||||||
|
inline SPROUT_CONSTEXPR int
|
||||||
|
get_day(RandomAccessIterator const& date) {
|
||||||
|
return sprout::detail::get_num(date[0]) * 10
|
||||||
|
+ sprout::detail::get_num(date[1])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
template<typename RandomAccessIterator>
|
||||||
|
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<typename RandomAccessIterator>
|
||||||
|
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<typename RandomAccessIterator1, typename RandomAccessIterator2>
|
||||||
|
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
|
|
@ -17,6 +17,7 @@
|
||||||
#include <sprout/type/integral_array.hpp>
|
#include <sprout/type/integral_array.hpp>
|
||||||
#include <sprout/type/string.hpp>
|
#include <sprout/type/string.hpp>
|
||||||
#include <sprout/type/uniform_types.hpp>
|
#include <sprout/type/uniform_types.hpp>
|
||||||
|
#include <sprout/type/packer.hpp>
|
||||||
#include <sprout/type/rebind_types.hpp>
|
#include <sprout/type/rebind_types.hpp>
|
||||||
#include <sprout/type/map_types.hpp>
|
#include <sprout/type/map_types.hpp>
|
||||||
#include <sprout/type/joint_types.hpp>
|
#include <sprout/type/joint_types.hpp>
|
||||||
|
|
139
sprout/type/packer.hpp
Normal file
139
sprout/type/packer.hpp
Normal file
|
@ -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 <tuple>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/type/type_tuple.hpp>
|
||||||
|
#include <sprout/type/tuple.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
namespace types {
|
||||||
|
//
|
||||||
|
// packer
|
||||||
|
//
|
||||||
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<typename... Types>
|
||||||
|
using packer = sprout::types::type_tuple<Types...>;
|
||||||
|
#else // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<typename... Types>
|
||||||
|
struct packer
|
||||||
|
: public sprout::types::type_tuple<Types...>
|
||||||
|
{};
|
||||||
|
#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<typename... Types>
|
||||||
|
struct tuple_size<sprout::types::packer<Types...> >
|
||||||
|
: public std::tuple_size<sprout::types::type_tuple<Types...> >
|
||||||
|
{};
|
||||||
|
|
||||||
|
//
|
||||||
|
// tuple_element
|
||||||
|
//
|
||||||
|
template<std::size_t I, typename... Types>
|
||||||
|
struct tuple_element<I, sprout::types::packer<Types...> >
|
||||||
|
: public sprout::types::tuple_element<I, sprout::types::packer<Types...> >
|
||||||
|
{};
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
} // namespace std
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
//
|
||||||
|
// tuple_get
|
||||||
|
//
|
||||||
|
template<std::size_t I, typename... Types>
|
||||||
|
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::types::packer<Types...> >::type
|
||||||
|
tuple_get(sprout::types::packer<Types...>) SPROUT_NOEXCEPT {
|
||||||
|
static_assert(I < sizeof...(Values), "tuple_get: index out of range");
|
||||||
|
typedef typename std::tuple_element<I, sprout::types::packer<Types...> >::type type;
|
||||||
|
return type();
|
||||||
|
}
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #if !SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
|
||||||
|
#include <sprout/index_tuple/metafunction.hpp>
|
||||||
|
#include <sprout/type/algorithm/contains.hpp>
|
||||||
|
#include <sprout/tpp/algorithm/all_of.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
namespace types {
|
||||||
|
//
|
||||||
|
// is_contained_in
|
||||||
|
//
|
||||||
|
template<typename T, typename... Types>
|
||||||
|
struct is_contained_in
|
||||||
|
: public sprout::types::contains<sprout::types::type_tuple<Types...>, T>
|
||||||
|
{};
|
||||||
|
|
||||||
|
//
|
||||||
|
// contains_types
|
||||||
|
//
|
||||||
|
namespace detail {
|
||||||
|
template<typename T, typename U, typename IndexTuple>
|
||||||
|
struct contains_types_impl;
|
||||||
|
template<typename T, typename U, sprout::index_t... Indexes>
|
||||||
|
struct contains_types_impl<T, U, sprout::index_tuple<Indexes...> >
|
||||||
|
: public sprout::tpp::all_of<sprout::types::is_contained_in<typename sprout::types::tuple_element<Indexes, U>::type, T>...>
|
||||||
|
{};
|
||||||
|
} // namespace detail
|
||||||
|
template<typename T, typename U>
|
||||||
|
struct contains_types
|
||||||
|
: public sprout::types::detail::contains_types_impl<T, U, typename sprout::make_index_tuple<sprout::types::tuple_size<U>::value>::type>
|
||||||
|
{};
|
||||||
|
|
||||||
|
#if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
template<typename T, typename... Types>
|
||||||
|
using is_contained_in_t = typename sprout::types::is_contained_in<T, Types...>::type;
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
using contains_types_t = typename sprout::types::contains_types<T, U>::type;
|
||||||
|
#endif // #if SPROUT_USE_TEMPLATE_ALIASES
|
||||||
|
|
||||||
|
#if SPROUT_USE_VARIABLE_TEMPLATES
|
||||||
|
template<typename T, typename... Types>
|
||||||
|
SPROUT_STATIC_CONSTEXPR bool is_contained_in_v = sprout::types::is_contained_in<T, Types...>::value;
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
SPROUT_STATIC_CONSTEXPR bool contains_types_v = sprout::types::contains_types<T, U>::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
|
|
@ -37,6 +37,8 @@ namespace sprout {
|
||||||
template<typename... Types>
|
template<typename... Types>
|
||||||
SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::types::type_tuple<Types...>::static_size;
|
SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::types::type_tuple<Types...>::static_size;
|
||||||
} // namespace types
|
} // namespace types
|
||||||
|
|
||||||
|
using sprout::types::type_tuple;
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_TYPE_TYPE_TUPLE_HPP
|
#endif // #ifndef SPROUT_TYPE_TYPE_TUPLE_HPP
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <sprout/cstdint.hpp>
|
#include <sprout/cstdint.hpp>
|
||||||
#include <sprout/cstdlib.hpp>
|
#include <sprout/cstdlib.hpp>
|
||||||
#include <sprout/cstring.hpp>
|
#include <sprout/cstring.hpp>
|
||||||
|
#include <sprout/ctime.hpp>
|
||||||
#include <sprout/ctype.hpp>
|
#include <sprout/ctype.hpp>
|
||||||
#include <sprout/current_function.hpp>
|
#include <sprout/current_function.hpp>
|
||||||
#include <sprout/cwchar.hpp>
|
#include <sprout/cwchar.hpp>
|
||||||
|
|
Loading…
Reference in a new issue