3 #if !defined(CPPLINQ_LINQ_UTIL_HPP) 4 #define CPPLINQ_LINQ_UTIL_HPP 7 namespace cpplinq {
namespace util {
9 template <
class Container>
12 typedef typename std::iterator_traits<iterator>::value_type
value_type;
17 std::is_reference<typename std::iterator_traits<iterator>::reference>::value
18 && std::is_same<typename std::remove_cv<value_type>::type,
19 typename std::remove_cv<typename std::remove_reference<typename std::iterator_traits<iterator>::reference>::type>::type>::value
26 template <
class Container>
30 template <
class Container>
34 typedef typename Container::const_iterator
iterator;
39 template <
class Cat1,
class Cat2>
44 typedef struct {
char c1,c2; } no;
45 static yes invoke(Cat1);
46 static no invoke(...);
48 enum { value = (
sizeof(invoke(Cat2())) ==
sizeof(yes)) };
54 template <
class Cat1,
class Cat2>
57 less_or_equal_iterator_category<Cat2, Cat1>::value,
64 #define CppLinq_GET_ITERATOR_TYPE(TContainer) \ 65 decltype(begin(static_cast<TContainer*>(0))) 66 #define CppLinq_GET_CONST_ITERATOR_TYPE(TContainer) \ 67 decltype(begin(static_cast<const TContainer*>(0))) 69 #define CppLinq_GET_ITERATOR_TYPE(TContainer) \ 70 typename ::cpplinq::util::container_traits<TContainer>::iterator 71 #define CppLinq_GET_CONST_ITERATOR_TYPE(TContainer) \ 72 typename ::cpplinq::util::container_traits<TContainer>::const_iterator 76 #if defined(_MSC_VER) && _MSC_VER >= 1600 78 template <
class T> T instance();
80 template <
class Fn>
struct result_of;
82 struct result_of<Fn()> {
83 typedef decltype(detail::instance<Fn>()()) type;
85 template <
class Fn,
class A0>
86 struct result_of<Fn(A0)> {
87 typedef decltype(detail::instance<Fn>()(detail::instance<A0>())) type;
89 template <
class Fn,
class A0,
class A1>
90 struct result_of<Fn(A0,A1)> {
91 typedef decltype(detail::instance<Fn>()(detail::instance<A0>(),
92 detail::instance<A1>())) type;
94 template <
class Fn,
class A0,
class A1,
class A2>
95 struct result_of<Fn(A0,A1,A2)> {
96 typedef decltype(detail::instance<Fn>()(detail::instance<A0>(),
97 detail::instance<A1>(),
98 detail::instance<A2>())) type;
100 template <
class Fn,
class A0,
class A1,
class A2,
class A3>
101 struct result_of<Fn(A0,A1,A2,A3)> {
102 typedef decltype(detail::instance<Fn>()(detail::instance<A0>(),
103 detail::instance<A1>(),
104 detail::instance<A2>(),
105 detail::instance<A3>())) type;
107 #elif defined(_MSC_VER) 109 struct result_of<T> : std::tr1::result_of<T> {};
111 using std::result_of;
141 typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type
152 new (
reinterpret_cast<T*
>(&storage)) T(value);
160 new (
reinterpret_cast<T*
>(&storage)) T(*other.
get());
168 new (
reinterpret_cast<T*
>(&storage)) T(std::move(*other.get()));
183 reinterpret_cast<T*
>(&storage)->~T();
188 return is_set ?
reinterpret_cast<T*
>(&storage) : 0;
191 const T*
get()
const {
192 return is_set ?
reinterpret_cast<const T*
>(&storage) : 0;
197 *
reinterpret_cast<T*
>(&storage) = std::move(value);
199 new (
reinterpret_cast<T*
>(&storage)) T(std::move(value));
213 if (
const T* pother = other.
get()) {
222 operator T*() {
return get(); }
223 operator const T*()
const {
return get(); }
231 #endif //CPPLINQ_UTIL_HPP maybe & operator=(const maybe &other)
Definition: util.hpp:212
maybe(const maybe &other)
Definition: util.hpp:156
const T * operator->() const
Definition: util.hpp:207
Type type
Definition: util.hpp:117
std::iterator_traits< iterator >::value_type value_type
Definition: util.hpp:12
T & operator*()
Definition: util.hpp:204
maybe & operator=(const T &other)
Definition: util.hpp:209
std::iterator_traits< iterator >::iterator_category iterator_category
Definition: util.hpp:13
Type operator()(const Type &left) const
Definition: util.hpp:118
~maybe()
Definition: util.hpp:174
T * operator->()
Definition: util.hpp:206
maybe()
Definition: util.hpp:144
const T & operator*() const
Definition: util.hpp:205
value_ptr(const T &value)
Definition: util.hpp:126
T * get()
Definition: util.hpp:187
Container::iterator iterator
Definition: util.hpp:11
Container::const_iterator iterator
Definition: util.hpp:34
maybe(T value)
Definition: util.hpp:149
maybe(maybe &&other)
Definition: util.hpp:164
void reset()
Definition: util.hpp:179
T value
Definition: util.hpp:125
const T * operator->()
Definition: util.hpp:130
value_ptr(const T *pvalue)
Definition: util.hpp:128