forb
shareable.hpp
1 //
2 // Created by gabriele on 18/11/18.
3 //
4 
5 #ifndef FORBCC_SHAREABLE_H
6 #define FORBCC_SHAREABLE_H
7 
8 #include <memory>
9 
10 namespace forbcc {
12  template<typename T>
13  class shareable {
14 
15  /* *************************************************** ALIAS **************************************************** */
16  public:
18  using const_T = typename std::add_const<T>::type;
19 
21  using ptr_t = std::shared_ptr<T>;
22 
24  using ptr_const_t = std::shared_ptr<const_T>;
25 
26  /* *************************************************** STATIC *************************************************** */
27 
30  template<typename ...Args>
31  static ptr_t new_ptr(Args &&... args) {
32  return std::make_shared<T>(args...);
33  }
34 
37  template<typename ...Args>
38  static ptr_const_t new_ptr_const(Args &&... args) {
39  return std::make_shared<const_T>(args...);
40  }
41 
42  };
43 
44 } // namespace forbcc
45 
46 #endif //FORBCC_SHAREABLE_H
typename std::add_const< module >::type const_T
Alias to the same type T, but with const qualifier.
Definition: shareable.hpp:18
static ptr_t new_ptr(Args &&... args)
Calls the constructor of the class with the given arguments to create a shared_pointer to T...
Definition: shareable.hpp:31
std::shared_ptr< const_T > ptr_const_t
Alias to std::shared_ptr<const T>
Definition: shareable.hpp:24
A template that can be used to ease the declaration of a shared_pointer of a given type...
Definition: shareable.hpp:13
Definition: code_ostream.hpp:11
std::shared_ptr< module > ptr_t
Alias to std::shared_ptr<T>
Definition: shareable.hpp:21
static ptr_const_t new_ptr_const(Args &&... args)
Calls the constructor of the class with the given arguments to create a shared_pointer to a const T...
Definition: shareable.hpp:38