has_component.hpp 3.1 KB
Newer Older
Armin Sobhani's avatar
Armin Sobhani committed
1
2
3
4
5
6
7
8
9
//----------------------------------------------------------------------------//
//  Copyright (c) 2018 Armin Sobhani <arminms@gmail.com>
//
//  Distributed under the Boost Software License Version 1.0.
//  (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)
//
//----------------------------------------------------------------------------//

10
11
#ifndef BOOST_BIOSEQ_HAS_COMPONENT_HPP
#define BOOST_BIOSEQ_HAS_COMPONENT_HPP
Armin Sobhani's avatar
Armin Sobhani committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

namespace boost {
namespace bioseq {

//----------------------------------------------------------------------------//

#define GENERATE_HAS_COMPONENT(component)                                      \
                                                                               \
template < class T >                                                           \
class Has_##component                                                          \
{                                                                              \
private:                                                                       \
    template<typename U, U> struct Check;                                      \
    using Yes = char[2];                                                       \
    using  No = char[1];                                                       \
                                                                               \
    struct Fallback { int component; };                                        \
    struct Derived : T, Fallback { };                                          \
                                                                               \
    template < class U >                                                       \
    static No& test (Check<int Fallback::*, &U::component> *);                 \
    template < typename U >                                                    \
    static Yes& test ( U* );                                                   \
                                                                               \
public:                                                                        \
    BOOST_STATIC_CONSTEXPR bool RESULT =                                       \
        sizeof(test<Derived>(nullptr)) == sizeof(Yes);                         \
};                                                                             \
                                                                               \
template < class T >                                                           \
struct has_##component                                                         \
: public std::integral_constant<bool, Has_##component<T>::RESULT>              \
{ };

//----------------------------------------------------------------------------//

48
49
50
GENERATE_HAS_COMPONENT(c_str)                // create has_c_str
GENERATE_HAS_COMPONENT(name_component)       // create has_name_component
GENERATE_HAS_COMPONENT(description_component)// create has_description_component
Armin Sobhani's avatar
Armin Sobhani committed
51
52
53
54
55
56

//----------------------------------------------------------------------------//

} // end bioseq namespace
} // end boost namespace

57
#endif  // BOOST_BIOSEQ_HAS_COMPONENT_HPP