SUNphi  1.0
CRTP.hpp
Go to the documentation of this file.
1 #ifndef _CRTP_HPP
2 #define _CRTP_HPP
3 
4 /// \file CRTP.hpp
5 ///
6 /// \brief Support for Curiously Recurring Template Pattern
7 
8 #include <metaprogramming/SwallowSemicolon.hpp>
9 
10 namespace SUNphi
11 {
12  /// Perform the cast to base class needed for CRTP
13  ///
14  /// Overload the ~ operator to implement cast to the basic class of a
15  /// CRTP class
16 #define PROVIDE_CRTP_CAST_OPERATOR(CLASS)
17  /*! Cast operator to class \c CLASS*/
18  CLASS& operator~()
19  {
20  return
21  *static_cast<CLASS*>(this);
22  }
23 
24  /*! Constant cast operator to class \c CLASS */
25  const CLASS& operator~() const
26  {
27  return
28  *static_cast<const CLASS*>(this);
29  }
30 
31  /// Access to the inheriting class
32 #define CRTP_THIS
33  (~*this)
34 }
35 
36 #endif