1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

sprout/tuple/sscrisk/cel/utility.hpp 追加

This commit is contained in:
bolero-MURAKAMI 2011-10-31 20:10:07 +09:00
parent a7b415f2b1
commit 871f9179c4
6 changed files with 121 additions and 10 deletions

View file

@ -27,6 +27,8 @@ namespace sprout {
return std::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_TUPLE_COMPARISON_HPP

View file

@ -27,6 +27,8 @@ namespace sprout {
return std::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP

View file

@ -0,0 +1,98 @@
#ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP
#define SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP
#include <cstddef>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sscrisk/cel/utility.hpp>
namespace sprout {
namespace tuples {
//
// tuple_size
//
template<typename T1, typename T2>
struct tuple_size<sscrisk::cel::pair<T1, T2> >
: public std::integral_constant<std::size_t, 2>
{};
//
// tuple_element
//
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
template<typename T1, typename T2>
struct tuple_element_impl<0, sscrisk::cel::pair<T1, T2> > {
public:
typedef T1 type;
};
template<typename T1, typename T2>
struct tuple_element_impl<1, sscrisk::cel::pair<T1, T2> > {
public:
typedef T2 type;
};
} // namespace detail
template<std::size_t I, typename T1, typename T2>
struct tuple_element<I, sscrisk::cel::pair<T1, T2> >
: public sprout::tuples::detail::tuple_element_impl<I, sscrisk::cel::pair<T1, T2> >
{};
//
// get
//
namespace detail {
template<std::size_t I, typename T>
struct get_impl;
template<typename T1, typename T2>
struct get_impl<0, sscrisk::cel::pair<T1, T2> > {
public:
T1& operator()(sscrisk::cel::pair<T1, T2>& t) const {
return t.first;
}
T1 const& operator()(sscrisk::cel::pair<T1, T2> const& t) const {
return t.first;
}
};
template<typename T1, typename T2>
struct get_impl<1, sscrisk::cel::pair<T1, T2> > {
public:
public:
T2& operator()(sscrisk::cel::pair<T1, T2>& t) const {
return t.second;
}
T2 const& operator()(sscrisk::cel::pair<T1, T2> const& t) const {
return t.second;
}
};
} // namespace detail
template<std::size_t I, typename T1, typename T2>
typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type& get(
sscrisk::cel::pair<T1, T2>& t
) SPROUT_NOEXCEPT
{
static_assert(I < 2, "get: index out of range");
return sprout::tuples::detail::get_impl<I, sscrisk::cel::pair<T1, T2> >()(t);
}
template<std::size_t I, typename T1, typename T2>
SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type const& get(
sscrisk::cel::pair<T1, T2> const& t
) SPROUT_NOEXCEPT
{
static_assert(I < 2, "get: index out of range");
return sprout::tuples::detail::get_impl<I, sscrisk::cel::pair<T1, T2> >()(t);
}
template<std::size_t I, typename T1, typename T2>
typename sprout::tuples::tuple_element<I, sscrisk::cel::pair<T1, T2> >::type&& get(
sscrisk::cel::pair<T1, T2>&& t
) SPROUT_NOEXCEPT
{
return std::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP

View file

@ -27,6 +27,8 @@ namespace sprout {
return std::move(sprout::tuples::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_STRING_HPP

View file

@ -261,6 +261,18 @@ namespace sprout {
return sprout::tuples::tuple<Types&...>(args...);
}
//
// swap
//
template<typename... Types>
inline void swap(
sprout::tuples::tuple<Types...>& lhs,
sprout::tuples::tuple<Types...>& rhs
) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
{
lhs.swap(rhs);
}
namespace detail {
template<std::size_t I, typename T>
struct tuple_element_impl;
@ -281,6 +293,7 @@ namespace sprout {
using sprout::tuples::make_tuple;
using sprout::tuples::forward_as_tuple;
using sprout::tuples::tie;
using sprout::tuples::swap;
} // namespace sprout
namespace std {
@ -325,7 +338,8 @@ namespace sprout {
template<std::size_t I, typename T>
SPROUT_CONSTEXPR auto get(
T&& t
) SPROUT_NOEXCEPT -> decltype(std::get<I>(sprout::forward<T>(t)))
) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::get<I>(sprout::forward<T>(t))))
-> decltype(std::get<I>(sprout::forward<T>(t)))
{
return std::get<I>(sprout::forward<T>(t));
}
@ -371,20 +385,11 @@ namespace sprout {
{
return sprout::tuples::detail::get_helper<I>(t);
}
//
// swap
//
template<typename... Types>
inline void swap(tuple<Types...>& lhs, tuple<Types...>& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) {
lhs.swap(rhs);
}
} // namespace tuples
using sprout::tuples::tuple_size;
using sprout::tuples::tuple_element;
using sprout::tuples::get;
using sprout::tuples::swap;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP

View file

@ -27,6 +27,8 @@ namespace sprout {
return std::move(std::get<I>(t));
}
} // namespace tuples
using sprout::tuples::get;
} // namespace sprout
#endif // #ifndef SPROUT_TUPLE_UUID_HPP