All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
object_with_copy.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 //=======================================================================
16 #ifndef PAAL_OBJECT_WITH_COPY_HPP
17 #define PAAL_OBJECT_WITH_COPY_HPP
18 
19 namespace paal {
20 namespace data_structures {
21 
33 template <typename T> class object_with_copy {
34  public:
35  typedef T ObjectType;
36 
42  object_with_copy(T t) : m_obj(std::move(t)), m_copy(m_obj) {}
43 
55  // if you use *. in decltype instead of -> you get
56  // "sorry, unimplemented: mangling dotstar_expr" :)
57  template <typename F, typename... Args>
58  typename std::result_of<F(T*, Args...)>::type
59  invoke(F f, Args... args) {
60  (m_copy.*(f))(args...);
61  return (m_obj.*(f))(args...);
62  }
63 
75  template <typename F, typename... Args>
76  typename std::result_of<F(T*, Args...)>::type
77  invoke_on_copy(F f, Args... args) const {
78  return (m_copy.*(f))(args...);
79  }
80 
86  const T *operator->() const { return &m_obj; }
87 
93  T &get_obj() { return m_obj; }
94 
100  const T &get_obj() const { return m_obj; }
101 
102  private:
106  T m_obj;
110  mutable T m_copy;
111 };
112 
113 } // data_structures
114 } // paal
115 
116 #endif // PAAL_OBJECT_WITH_COPY_HPP
const T & get_obj() const
getter for inner object
std::result_of< F(T *, Args...)>::type invoke_on_copy(F f, Args...args) const
invokes member function on copy
std::result_of< F(T *, Args...)>::type invoke(F f, Args...args)
invokes member function on object and copy
T & get_obj()
getter for inner object
const T * operator->() const
easier way for invoking const member functions
keeps object and its copy. Invoke all the member functions on both: object and its copy...