HoverRace  2.0
MPL.h
Go to the documentation of this file.
1 
2 // MPL.h
3 //
4 // Copyright (c) 2014, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
25 # ifdef MR_ENGINE
26 # define MR_DllDeclare __declspec( dllexport )
27 # else
28 # define MR_DllDeclare __declspec( dllimport )
29 # endif
30 #else
31 # define MR_DllDeclare
32 #endif
33 
34 namespace HoverRace {
35 namespace Display {
37 namespace MPL {
38 
40 template<class C>
41 struct HasSetSize
42 {
43 private:
44  template<class T>
45  static auto check(T*) ->
46  decltype(std::declval<T>().SetSize(std::declval<Vec2>()),
47  std::true_type());
48 
49  template<class>
50  static std::false_type check(...);
51 
52  using type = decltype(check<C>(nullptr));
53 
54 public:
55  static const bool value = type::value;
56 };
57 
58 template<class T>
59 typename std::enable_if<MPL::HasSetSize<T>::value, void>::type
60 inline SetSize(T &widget, double w, double h)
61 {
62  widget.SetSize(Vec2(w, h));
63 }
64 
65 template<class T>
66 typename std::enable_if<MPL::HasSetSize<T>::value, void>::type
67 inline SetSize(T &widget, Vec2 &&vec)
68 {
69  widget.SetSize(std::forward<Vec2>(vec));
70 }
71 
72 template<class T>
73 typename std::enable_if<!MPL::HasSetSize<T>::value, void>::type
74 inline SetSize(T&, double, double)
75 {
76  // Do nothing.
77 }
78 
79 template<class T>
80 typename std::enable_if<!MPL::HasSetSize<T>::value, void>::type
81 inline SetSize(T&, Vec2&&)
82 {
83  // Do nothing.
84 }
85 
86 } // namespace MPL
87 } // namespace Display
88 } // namespace HoverRace
89 
90 #undef MR_DllDeclare
std::enable_if< MPL::HasSetSize< T >::value, void >::type SetSize(T &widget, double w, double h)
Definition: MPL.h:60
decltype(check< C >(nullptr)) type
Definition: MPL.h:52
Definition: Vec.h:38
static const bool value
Definition: MPL.h:55
static auto check(T *) -> decltype(std::declval< T >().SetSize(std::declval< Vec2 >()), std::true_type())
Definition: Announcement.h:24
Determine if a class as a SetSize(Vec2).
Definition: MPL.h:41