YSTest: iterator_trait.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

iterator_trait.hpp
浏览该文件的文档.
1 /*
2 © 2014-2016, 2019 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_iterator_trait_hpp_
29 #define YB_INC_ystdex_iterator_trait_hpp_ 1
30
31 #include "type_traits.hpp" // for std::declval, enable_if_t, are_same,
32 // indirect_t, increment_t;
33 #include <iterator> // for std::iterator_traits;
34
35 namespace ystdex
36 {
37
39
40
44 template<class _tTag, typename _tIter>
45 struct has_iterator_category : is_convertible<typename
46 std::iterator_traits<_tIter>::iterator_category, _tTag>
47 {};
48
49
54 template<typename _type, typename _tIter>
55 using has_iterator_value_type
56 = is_same<typename std::iterator_traits<_tIter>::value_type, _type>;
58
59
65 template<class _tTag, typename... _tIters>
66 struct have_same_iterator_category : and_<is_convertible<
67 typename std::iterator_traits<_tIters>::iterator_category, _tTag>...>
68 {};
69
70
72 namespace details
73 {
74
75 template<typename _tParam>
76 using iterator_reqirement_t = is_same<increment_t<_tParam&>, _tParam&>;
77
78 template<typename _tParam>
79 using input_iterator_reqirement_t = and_<iterator_reqirement_t<_tParam>,
80 is_convertible<typename std::iterator_traits<_tParam>::iterator_category,
81 std::input_iterator_tag>>;
82
83 } // namespace details;
84
95 template<typename _tParam, typename _type = void, yimpl(typename
96 = indirect_t<_tParam&>, typename = increment_t<_tParam&>)>
97 using enable_for_iterator_t
98 = enable_if_t<details::iterator_reqirement_t<_tParam>::value, _type>;
99
104 template<typename _tParam, typename _type = void, yimpl(typename
105 = indirect_t<_tParam&>, typename = increment_t<_tParam&>)>
106 using enable_for_input_iterator_t
107 = enable_if_t<details::input_iterator_reqirement_t<_tParam>::value, _type>;
109
110 } // namespace ystdex;
111
112 #endif
113
ystdex::has_iterator_value_type
is_same< typename std::iterator_traits< _tIter >::value_type, _type > has_iterator_value_type
判断迭代器是否具有相同的指定的值类型。
Definition: iterator_trait.hpp:56
type_traits.hpp
ISO C++ 类型特征扩展。
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
ystdex::indirect_t
decltype(*std::declval< _type >()) indirect_t
Definition: type_traits.hpp:69
ystdex::has_iterator_category
判断迭代器是否具有相同的指定的类别。
Definition: iterator_trait.hpp:47
ystdex::increment_t
decltype(++std::declval< _type >()) increment_t
Definition: type_traits.hpp:78
ystdex::details::iterator_reqirement_t
is_same< increment_t< _tParam & >, _tParam & > iterator_reqirement_t
Definition: iterator_trait.hpp:76
ystdex::enable_for_input_iterator_t
enable_if_t< details::input_iterator_reqirement_t< _tParam >::value, _type > enable_for_input_iterator_t
选择输入迭代器类型的特定重载避免和其它类型冲突。
Definition: iterator_trait.hpp:107
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::enable_for_iterator_t
enable_if_t< details::iterator_reqirement_t< _tParam >::value, _type > enable_for_iterator_t
选择迭代器类型的特定重载避免和其它类型冲突。
Definition: iterator_trait.hpp:98
ystdex::have_same_iterator_category
判断若干个迭代器是否具有相同的指定的类别。
Definition: iterator_trait.hpp:68
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
NPL::_tParam
_tParam
Definition: NPLA.h:2367
ystdex::and_
逻辑操作元函数。
Definition: integral_constant.hpp:151