All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
type_functions.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_TYPE_FUNCTIONS_HPP
16 #define PAAL_TYPE_FUNCTIONS_HPP
17 
18 #include <boost/range.hpp>
19 
20 #include <type_traits>
21 #include <utility>
22 #include <tuple>
23 
24 namespace paal {
25 
26 //TODO, remove when appears in the standard
28 template <typename T>
29 using decay_t = typename std::decay<T>::type;
30 
32 #define puretype(t) typename std::decay<decltype(t)>::type
33 
35 template <typename Range>
36 using range_to_ref_t = typename boost::range_reference<Range>::type;
37 
39 template <typename Range>
40 using range_to_elem_t = typename boost::range_value<Range>::type;
41 
43 template <typename Range>
44 using range_to_diff_type_t = typename boost::range_difference<Range>::type;
45 
46 namespace detail {
47 
48  template <typename T, int k>
49  struct k_tuple {
50  using type = decltype(
51  std::tuple_cat(std::declval<std::tuple<T>>(),
52  std::declval<typename k_tuple<T, k - 1>::type>()));
53  };
54 
55  template <typename T>
56  struct k_tuple<T, 1> {using type = std::tuple<T>;};
57 }
58 
60 template <typename T, int k>
61 using k_tuple_t = typename detail::k_tuple<T, k>::type;
62 
64 template <class F>
65 using pure_result_of_t = typename std::decay<typename std::result_of<F>::type>::type;
66 
68 template <typename T1, typename T2>
69 using promote_with_t = puretype(std::declval<T1>() + std::declval<T2>());
70 
72 template <typename T>
74 
75 }
76 
77 #endif // PAAL_TYPE_FUNCTIONS_HPP
typename boost::range_value< Range >::type range_to_elem_t
for given range returns type of its element
typename std::decay< T >::type decay_t
short version of std::decay
promote_with_t< T, double > promote_with_double_t
return type after promotion with double
typename detail::k_tuple< T, k >::type k_tuple_t
returns tuple consisting of k times type T
#define puretype(t)
for given expression returns its type with removed const and reference
typename boost::range_difference< Range >::type range_to_diff_type_t
for given collection returns its difference type
typename std::decay< typename std::result_of< F >::type >::type pure_result_of_t
return pure type of function (decays const and reference)
puretype(std::declval< T1 >()+std::declval< T2 >()) promote_with_t
return type obtained after adding values of given types
typename boost::range_reference< Range >::type range_to_ref_t
for given range returns type of its reference