ttvalue.h
Go to the documentation of this file.
1 #ifndef TTG_PARSEC_TTVALUE_H
2 #define TTG_PARSEC_TTVALUE_H
3 
4 #include <type_traits>
5 
7 
8 namespace ttg_parsec {
9 
16  template<typename DerivedT>
17  struct TTValue : private ttg_parsec::detail::ttg_data_copy_container_setter<ttg_parsec::detail::ttg_data_copy_t>
19 
20  using derived_type = std::decay_t<DerivedT>;
21 
22  /* Constructor called with a pointer to the derived class object */
25  , ttg_data_copy_t()
26  { }
27 
28  /* default copy ctor */
29  TTValue(const TTValue& v)
31  , ttg_data_copy_t(v)
32  { }
33 
34  /* default move ctor */
37  , ttg_data_copy_t(std::move(v))
38  { }
39 
40  /* virtual mark destructor */
41  virtual ~TTValue() = default;
42 
43  /* default copy operator */
44  TTValue& operator=(const TTValue& v) {
46  ttg_data_copy_t::operator=(v);
47  return *this;
48  }
49 
50  /* default move operator */
53  ttg_data_copy_t::operator=(std::move(v));
54  return *this;
55  }
56 
57  virtual void* get_ptr() override final {
58  return static_cast<DerivedT*>(this);
59  }
60 
62  return *static_cast<DerivedT*>(this);
63  }
64 
65  const derived_type& get_derived() const {
66  return *static_cast<DerivedT*>(this);
67  }
68  };
69 
70  namespace detail {
71 
72  template<typename T, typename Enabler = void>
73  struct is_ttvalue_base : std::false_type {};
74 
75  template<typename T>
76  struct is_ttvalue_base<T, std::is_base_of<TTValue<std::decay_t<T>>, std::decay_t<T>>>
77  : std::true_type
78  { };
79 
80  template<typename T>
81  static constexpr const bool is_ttvalue_base_v = is_ttvalue_base<T>::value;
82 
83  template<typename ValueT>
85  using reference_type = ValueT;
86  using value_type = std::decay_t<ValueT>;
87  using lvalue_reference_type = std::add_lvalue_reference_t<std::remove_reference_t<ValueT>>;
89  };
90  } // namespace detail
91 
92  template<typename ValueT>
93  inline auto persistent(ValueT&& value) {
94  if constexpr (std::is_base_of_v<TTValue<std::decay_t<ValueT>>, std::decay_t<ValueT>>) {
96  } else {
97  return std::forward<ValueT>(value);
98  }
99  }
100 
101 } // namespace ttg_parsec
102 
103 #endif // TTG_PARSEC_TTVALUE_H
ttg_data_copy_t *& ttg_data_copy_container()
Definition: thread_local.h:14
this contains PaRSEC-based TTG functionality
Definition: fwd.h:18
auto persistent(ValueT &&value)
Definition: ttvalue.h:93
TTValue(TTValue &&v)
Definition: ttvalue.h:35
virtual void * get_ptr() override final
Definition: ttvalue.h:57
std::decay_t< DerivedT > derived_type
Definition: ttvalue.h:20
derived_type & get_derived()
Definition: ttvalue.h:61
TTValue & operator=(TTValue &&v)
Definition: ttvalue.h:51
const derived_type & get_derived() const
Definition: ttvalue.h:65
virtual ~TTValue()=default
TTValue & operator=(const TTValue &v)
Definition: ttvalue.h:44
TTValue(const TTValue &v)
Definition: ttvalue.h:29
std::add_lvalue_reference_t< std::remove_reference_t< ValueT > > lvalue_reference_type
Definition: ttvalue.h:87
lvalue_reference_type value_ref
Definition: ttvalue.h:88
std::decay_t< ValueT > value_type
Definition: ttvalue.h:86