PageRenderTime 17ms CodeModel.GetById 10ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/contrib/boost/spirit/home/support/detail/make_cons.hpp

http://pythonocc.googlecode.com/
C++ Header | 85 lines | 65 code | 10 blank | 10 comment | 5 complexity | 11e2a36740b7d49df002b36439721cf8 MD5 | raw file
 1/*=============================================================================
 2  Copyright (c) 2001-2010 Joel de Guzman
 3  http://spirit.sourceforge.net/
 4
 5  Distributed under the Boost Software License, Version 1.0. (See accompanying
 6  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 7=============================================================================*/
 8#ifndef BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM
 9#define BOOST_SPIRIT_MAKE_CONS_OCTOBER_16_2008_1252PM
10
11#if defined(_MSC_VER)
12#pragma once
13#endif
14
15#include <boost/proto/proto.hpp>
16#include <boost/mpl/eval_if.hpp>
17#include <boost/fusion/include/cons.hpp>
18#include <boost/type_traits/remove_const.hpp>
19#include <boost/type_traits/is_abstract.hpp>
20#include <boost/type_traits/is_function.hpp>
21#include <boost/type_traits/add_reference.hpp>
22#include <boost/utility/enable_if.hpp>
23
24namespace boost { namespace spirit { namespace detail
25{
26    template <typename T>
27    struct as_meta_element
28      : mpl::eval_if_c<is_abstract<T>::value || is_function<T>::value
29          , add_reference<T>, remove_const<T> >
30    {};
31
32    template <typename T>
33    struct as_meta_element<T&> : as_meta_element<T>   // always store by value
34    {};
35
36    template <typename T, int N>
37    struct as_meta_element<T[N]>
38    {
39        typedef const T(&type)[N];
40    };
41
42    namespace result_of
43    {
44        template <typename Car, typename Cdr = fusion::nil>
45        struct make_cons
46        {
47            typedef typename as_meta_element<Car>::type car_type;
48            typedef typename fusion::cons<car_type, Cdr> type;
49        };
50    }
51
52    template <typename Car, typename Cdr>
53    fusion::cons<typename as_meta_element<Car>::type, Cdr>
54    make_cons(Car const& car, Cdr const& cdr)
55    {
56        typedef typename as_meta_element<Car>::type car_type;
57        typedef typename fusion::cons<car_type, Cdr> result;
58        return result(car, cdr);
59    }
60
61    template <typename Car>
62    fusion::cons<typename as_meta_element<Car>::type>
63    make_cons(Car const& car)
64    {
65        typedef typename as_meta_element<Car>::type car_type;
66        typedef typename fusion::cons<car_type> result;
67        return result(car);
68    }
69
70#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 0)
71    // workaround for gcc-4.0 bug where illegal function types
72    // can be formed (const is added to function type)
73    // description: http://lists.boost.org/Archives/boost/2009/04/150743.php
74    template <typename Car>
75    fusion::cons<typename as_meta_element<Car>::type>
76    make_cons(Car& car, typename enable_if<is_function<Car> >::type* = 0)
77    {
78        typedef typename as_meta_element<Car>::type car_type;
79        typedef typename fusion::cons<car_type> result;
80        return result(car);
81    }
82#endif
83}}}
84
85#endif