TooN
introspection.hh
1 // -*- c++ -*-
2 
3 // Copyright (C) 2012
4 // Ed Rosten (er258@cam.ac.uk)
5 
6 //All rights reserved.
7 //
8 //Redistribution and use in source and binary forms, with or without
9 //modification, are permitted provided that the following conditions
10 //are met:
11 //1. Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 //THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
18 //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 //IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 //ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
21 //LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 //CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 //SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 //INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 //CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 //POSSIBILITY OF SUCH DAMAGE.
28 
29 // Allocators always copy data on copy construction.
30 //
31 // When a Vector/Matrix is constructed from a different, but compatible type
32 // copying is done at a much higher level: above the level that knows how the
33 // data is laid out in memory.
34 //
35 // At this level, copy construction is required since it is only known here
36 // whether data or a reference to data should be copied.
37 
38 
41 namespace TooN{
42 namespace Internal{
43 //Fake function to pretend to return an instance of a type
44 template<class C>
45 const C& get();
46 
47 //Two typedefs guaranteed to have different sizes
48 typedef char OneSized[1];
49 typedef char TwoSized[2];
50 
51 
52 //Class to give us a size 2 return value or fail on
53 //substituting S
54 template<int S>
56 {
57  typedef TwoSized Type;
58 };
59 
60 
61 #define TOON_CREATE_THING_DETECTOR(Y, X, Z) \
62 template<class C>\
63 struct Has_##X##_##Z\
64 {\
65  static OneSized& detect_##X##_##Z(...);\
66 \
67  template<class S>\
68  static typename SFINAE_dummy<sizeof(Y)>::Type& detect_##X##_##Z(const S&);\
69 \
70  static const bool Has = sizeof(detect_##X##_##Z(get<C>())) == 2;\
71 }
72 
73 #define TOON_CREATE_MEMBER_DETECTOR(X) TOON_CREATE_THING_DETECTOR(S::X, X, Member)
74 #define TOON_CREATE_METHOD_DETECTOR(X) TOON_CREATE_THING_DETECTOR(&S::X, X, Method)
75 #define TOON_CREATE_TYPEDEF_DETECTOR(X) TOON_CREATE_THING_DETECTOR(typename S::X, X, Typedef)
76 
77 }}
Pretty generic SFINAE introspection generator.
Definition: vec_test.cc:21
Definition: introspection.hh:55