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

add type_traits/*

This commit is contained in:
bolero-MURAKAMI 2012-04-05 14:54:23 +09:00
parent 84956034ad
commit 64dd2582a4
13 changed files with 114 additions and 76 deletions

View file

@ -4,14 +4,14 @@
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/utility/operation.hpp>
#include <sprout/range/lvref_range.hpp>
#include <sprout/range/lvalue_range.hpp>
#include <sprout/algorithm/equal_range.hpp>
namespace sprout {
namespace range {
namespace detail {
template<typename Range, typename Pair>
inline SPROUT_CONSTEXPR typename sprout::range::lvref_range<Range>::type
inline SPROUT_CONSTEXPR typename sprout::range::lvalue_range<Range>::type
pair_to_range(Pair const& pair) {
return {pair.first, pair.second};
}
@ -21,7 +21,7 @@ namespace sprout {
// 25.4.3.3 equal_range
template<typename Range, typename T>
inline SPROUT_CONSTEXPR typename sprout::range::lvref_range<Range>::type
inline SPROUT_CONSTEXPR typename sprout::range::lvalue_range<Range>::type
equal_range(Range&& range, T const& value) {
return sprout::range::detail::pair_to_range<Range>(
sprout::equal_range(
@ -33,7 +33,7 @@ namespace sprout {
}
template<typename Range, typename T, typename Compare>
inline SPROUT_CONSTEXPR typename sprout::range::lvref_range<Range>::type
inline SPROUT_CONSTEXPR typename sprout::range::lvalue_range<Range>::type
equal_range(Range&& range, T const& value, Compare comp) {
return sprout::range::detail::pair_to_range<Range>(
sprout::equal_range(

View file

@ -5,7 +5,7 @@
#include <sprout/container/functions.hpp>
#include <sprout/utility/operation.hpp>
#include <sprout/utility/pair.hpp>
#include <sprout/range/lvref_iterator.hpp>
#include <sprout/range/lvalue_iterator.hpp>
#include <sprout/algorithm/mismatch.hpp>
namespace sprout {
@ -15,8 +15,8 @@ namespace sprout {
// 25.2.10 Mismatch
template<typename Range1, typename Range2>
inline SPROUT_CONSTEXPR sprout::pair<
typename sprout::range::lvref_iterator<Range1>::type,
typename sprout::range::lvref_iterator<Range2>::type
typename sprout::range::lvalue_iterator<Range1>::type,
typename sprout::range::lvalue_iterator<Range2>::type
>
mismatch(Range1&& range1, Range2&& range2) {
return sprout::mismatch(
@ -28,8 +28,8 @@ namespace sprout {
template<typename Range1, typename Range2, typename BinaryPredicate>
inline SPROUT_CONSTEXPR sprout::pair<
typename sprout::range::lvref_iterator<Range1>::type,
typename sprout::range::lvref_iterator<Range2>::type
typename sprout::range::lvalue_iterator<Range1>::type,
typename sprout::range::lvalue_iterator<Range2>::type
>
mismatch(Range1&& range1, Range2&& range2, BinaryPredicate pred) {
return sprout::mismatch(

View file

@ -0,0 +1,24 @@
#ifndef SPROUT_RANGE_LVALUE_ITERATOR_HPP
#define SPROUT_RANGE_LVALUE_ITERATOR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
namespace sprout {
namespace range {
//
// lvalue_iterator
//
template<typename Range>
struct lvalue_iterator {
public:
typedef typename sprout::container_traits<
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
>::iterator type;
};
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_LVALUE_ITERATOR_HPP

View file

@ -1,21 +1,21 @@
#ifndef SPROUT_RANGE_LVREF_RANGE_HPP
#define SPROUT_RANGE_LVREF_RANGE_HPP
#ifndef SPROUT_RANGE_LVALUE_RANGE_HPP
#define SPROUT_RANGE_LVALUE_RANGE_HPP
#include <sprout/config.hpp>
#include <sprout/range/range_container.hpp>
#include <sprout/range/lvref_iterator.hpp>
#include <sprout/range/lvalue_iterator.hpp>
namespace sprout {
namespace range {
//
// lvref_range
// lvalue_range
//
template<typename Range>
struct lvref_range {
struct lvalue_range {
public:
typedef sprout::range::range_container<typename sprout::range::lvref_iterator<Range>::type> type;
typedef sprout::range::range_container<typename sprout::range::lvalue_iterator<Range>::type> type;
};
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_LVREF_RANGE_HPP
#endif // #ifndef SPROUT_RANGE_LVALUE_RANGE_HPP

View file

@ -1,24 +0,0 @@
#ifndef SPROUT_RANGE_LVREF_ITERATOR_HPP
#define SPROUT_RANGE_LVREF_ITERATOR_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/utility/operation_ext.hpp>
namespace sprout {
namespace range {
//
// lvref_iterator
//
template<typename Range>
struct lvref_iterator {
public:
typedef typename sprout::container_traits<
typename std::remove_reference<typename sprout::lvref<Range>::type>::type
>::iterator type;
};
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_LVREF_ITERATOR_HPP

View file

@ -5,8 +5,8 @@
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/utility/operation.hpp>
#include <sprout/range/lvref_iterator.hpp>
#include <sprout/range/lvref_range.hpp>
#include <sprout/range/lvalue_iterator.hpp>
#include <sprout/range/lvalue_range.hpp>
namespace sprout {
namespace range {
@ -28,7 +28,7 @@ namespace sprout {
template<typename Range>
struct range_return<Range, sprout::range::return_found> {
public:
typedef typename sprout::range::lvref_iterator<Range>::type type;
typedef typename sprout::range::lvalue_iterator<Range>::type type;
public:
static SPROUT_CONSTEXPR type pack(
typename sprout::container_traits<Range>::iterator found,
@ -41,7 +41,7 @@ namespace sprout {
template<typename Range>
struct range_return<Range, sprout::range::return_found_end> {
public:
typedef typename sprout::range::lvref_range<Range>::type type;
typedef typename sprout::range::lvalue_range<Range>::type type;
public:
static SPROUT_CONSTEXPR type pack(
typename sprout::container_traits<Range>::iterator found,
@ -54,7 +54,7 @@ namespace sprout {
template<typename Range>
struct range_return<Range, sprout::range::return_begin_found> {
public:
typedef typename sprout::range::lvref_range<Range>::type type;
typedef typename sprout::range::lvalue_range<Range>::type type;
public:
static SPROUT_CONSTEXPR type pack(
typename sprout::container_traits<Range>::iterator found,

8
sprout/type_traits.hpp Normal file
View file

@ -0,0 +1,8 @@
#ifndef SPROUT_TYPE_TRAITS_HPP
#define SPROUT_TYPE_TRAITS_HPP
#include <sprout/config.hpp>
#include <sprout/type_traits/lvalue_reference.hpp>
#include <sprout/type_traits/const_reference.hpp>
#endif // #ifndef SPROUT_TYPE_TRAITS_HPP

View file

@ -0,0 +1,19 @@
#ifndef SPROUT_TYPE_TRAITS_CONST_REFERENCE_HPP
#define SPROUT_TYPE_TRAITS_CONST_REFERENCE_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/as_const.hpp>
namespace sprout {
//
// const_reference
//
template<typename T>
struct const_reference {
public:
typedef decltype(sprout::as_const(std::declval<T&&>())) type;
};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_CONST_REFERENCE_HPP

View file

@ -0,0 +1,19 @@
#ifndef SPROUT_TYPE_TRAITS_LVALUE_REFERENCE_HPP
#define SPROUT_TYPE_TRAITS_LVALUE_REFERENCE_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/as_lvalue.hpp>
namespace sprout {
//
// lvalue_reference
//
template<typename T>
struct lvalue_reference {
public:
typedef decltype(sprout::as_lvalue(std::declval<T&&>())) type;
};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_LVALUE_REFERENCE_HPP

View file

@ -2,7 +2,8 @@
#define SPROUT_UTILITY_HPP
#include <sprout/config.hpp>
#include <sprout/utility/operation.hpp>
#include <sprout/utility/pair.hpp>
#include <sprout/utility/operation.hpp>
#include <sprout/utility/operation_ext.hpp>
#endif // #ifndef SPROUT_UTILITY_HPP

View file

@ -0,0 +1,20 @@
#ifndef SPROUT_UTILITY_AS_LVALUE_HPP
#define SPROUT_UTILITY_AS_LVALUE_HPP
#include <sprout/config.hpp>
namespace sprout {
//
// as_lvalue
//
template<typename T>
inline T& as_lvalue(T& t) {
return t;
}
template<typename T>
inline SPROUT_CONSTEXPR T const& as_lvalue(T const& t) {
return t;
}
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_AS_LVALUE_HPP

View file

@ -1,29 +0,0 @@
#ifndef SPROUT_UTILITY_AS_LVREF_HPP
#define SPROUT_UTILITY_AS_LVREF_HPP
#include <sprout/config.hpp>
namespace sprout {
//
// as_lvref
//
template<typename T>
inline T& as_lvref(T& t) {
return t;
}
template<typename T>
inline SPROUT_CONSTEXPR T const& as_lvref(T const& t) {
return t;
}
//
// lvref
//
template<typename T>
struct lvref {
public:
typedef decltype(sprout::as_lvref(std::declval<T&&>())) type;
};
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_AS_LVREF_HPP

View file

@ -2,7 +2,7 @@
#define SPROUT_UTILITY_OPERATION_EXT_HPP
#include <sprout/config.hpp>
#include <sprout/utility/as_lvref.hpp>
#include <sprout/utility/as_lvalue.hpp>
#include <sprout/utility/as_const.hpp>
#endif // #ifndef SPROUT_UTILITY_OPERATION_EXT_HPP