Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
CRTP.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_CRTP_H_
9#define model_CRTP_H_
10
11namespace model {
12
17 template <typename Derived>
18 class CRTP
19 {
20
21 protected:
22
24 Derived& derived() { return *static_cast<Derived*>(this); }
25
27 Derived* p_derived() { return static_cast<Derived*>(this); }
28
30 const Derived& derived() const { return *static_cast<const Derived*>(this); }
31
33 const Derived* p_derived() const { return static_cast<const Derived*>(this); }
34
35 public:
37 CRTP(){
66 }
67
68 };
69
71} // namespace model
72#endif
Derived * p_derived()
A pointer to the derived object.
Definition CRTP.h:27
Derived & derived()
A reference to the derived object.
Definition CRTP.h:24
const Derived & derived() const
A reference to the const derived object.
Definition CRTP.h:30
CRTP()
The default constructor.
Definition CRTP.h:37
const Derived * p_derived() const
A pointer to the const derived object.
Definition CRTP.h:33