BVB Source Codes

mars Show dispatch_uses_allocator.hpp Source code

Return Download mars: download dispatch_uses_allocator.hpp Source code - Download mars Source code - Type:.hpp
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10.  
  11. #ifndef BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
  12. #define BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
  13.  
  14. #if defined (_MSC_VER)
  15. #  pragma once
  16. #endif
  17.  
  18. #include <boost/container/detail/config_begin.hpp>
  19. #include <boost/container/detail/workaround.hpp>
  20.  
  21. #include <boost/container/allocator_traits.hpp>
  22. #include <boost/container/uses_allocator.hpp>
  23.  
  24. #include <boost/container/detail/addressof.hpp>
  25. #include <boost/container/detail/mpl.hpp>
  26. #include <boost/container/detail/pair.hpp>
  27. #include <boost/container/detail/type_traits.hpp>
  28.  
  29. #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  30. #include <boost/move/detail/fwd_macros.hpp>
  31. #endif
  32. #include <boost/move/utility_core.hpp>
  33.  
  34. #include <boost/core/no_exceptions_support.hpp>
  35.  
  36. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace container {
  37.  
  38. namespace container_detail {
  39.  
  40.  
  41. // Check if we can detect is_convertible using advanced SFINAE expressions
  42. #if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  43.  
  44.    //! Code inspired by Mathias Gaunard's is_convertible.cpp found in the Boost mailing list
  45.    //! http://boost.2283326.n4.nabble.com/type-traits-is-constructible-when-decltype-is-supported-td3575452.html
  46.    //! Thanks Mathias!
  47.  
  48.    //With variadic templates, we need a single class to implement the trait
  49.    template<class T, class ...Args>
  50.    struct is_constructible
  51.    {
  52.       typedef char yes_type;
  53.       struct no_type
  54.       { char padding[2]; };
  55.  
  56.       template<std::size_t N>
  57.       struct dummy;
  58.  
  59.       template<class X>
  60.       static decltype(X(mars_boost::move_detail::declval<Args>()...), true_type()) test(int);
  61.  
  62.       template<class X>
  63.       static no_type test(...);
  64.  
  65.       static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
  66.    };
  67.  
  68.    template <class T, class InnerAlloc, class ...Args>
  69.    struct is_constructible_with_allocator_prefix
  70.       : is_constructible<T, allocator_arg_t, InnerAlloc, Args...>
  71.    {};
  72.  
  73. #else    // #if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  74.  
  75.    //Without advanced SFINAE expressions, we can't use is_constructible
  76.    //so backup to constructible_with_allocator_xxx
  77.  
  78.    #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  79.  
  80.    template <class T, class InnerAlloc, class ...Args>
  81.    struct is_constructible_with_allocator_prefix
  82.       : constructible_with_allocator_prefix<T>
  83.    {};
  84.  
  85.    template <class T, class InnerAlloc, class ...Args>
  86.    struct is_constructible_with_allocator_suffix
  87.       : constructible_with_allocator_suffix<T>
  88.    {};
  89.  
  90.    #else    // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  91.  
  92.    template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
  93.    struct is_constructible_with_allocator_prefix
  94.       : constructible_with_allocator_prefix<T>
  95.    {};
  96.  
  97.    template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
  98.    struct is_constructible_with_allocator_suffix
  99.       : constructible_with_allocator_suffix<T>
  100.    {};
  101.  
  102.    #endif   // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  103.  
  104. #endif   // #if !defined(BOOST_NO_SFINAE_EXPR)
  105.  
  106. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  107.  
  108. template < typename ConstructAlloc
  109.          , typename ArgAlloc
  110.          , typename T
  111.          , class ...Args
  112.          >
  113. inline typename container_detail::enable_if_and
  114.    < void
  115.    , container_detail::is_not_pair<T>
  116.    , container_detail::not_< uses_allocator<T, ArgAlloc> >
  117.    >::type dispatch_uses_allocator
  118.    ( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
  119. {
  120.    (void)arg_alloc;
  121.    allocator_traits<ConstructAlloc>::construct(construct_alloc, p, ::mars_boost::forward<Args>(args)...);
  122. }
  123.  
  124. // allocator_arg_t
  125. template < typename ConstructAlloc
  126.          , typename ArgAlloc
  127.          , typename T
  128.          , class ...Args
  129.          >
  130. inline typename container_detail::enable_if_and
  131.    < void
  132.    , container_detail::is_not_pair<T>
  133.    , uses_allocator<T, ArgAlloc>
  134.    , is_constructible_with_allocator_prefix<T, ArgAlloc, Args...>
  135.    >::type dispatch_uses_allocator
  136.    ( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args) ...args)
  137. {
  138.    allocator_traits<ConstructAlloc>::construct
  139.       ( construct_alloc, p, allocator_arg
  140.       , ::mars_boost::forward<ArgAlloc>(arg_alloc), ::mars_boost::forward<Args>(args)...);
  141. }
  142.  
  143. // allocator suffix
  144. template < typename ConstructAlloc
  145.          , typename ArgAlloc
  146.          , typename T
  147.          , class ...Args
  148.          >
  149. inline typename container_detail::enable_if_and
  150.    < void
  151.    , container_detail::is_not_pair<T>
  152.    , uses_allocator<T, ArgAlloc>
  153.    , container_detail::not_<is_constructible_with_allocator_prefix<T, ArgAlloc, Args...> >
  154.    >::type dispatch_uses_allocator
  155.    ( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
  156. {
  157.    allocator_traits<ConstructAlloc>::construct
  158.       (construct_alloc, p, ::mars_boost::forward<Args>(args)..., ::mars_boost::forward<ArgAlloc>(arg_alloc));
  159. }
  160.  
  161. #else    //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  162.  
  163. #define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
  164.    template <typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  165.    inline typename container_detail::enable_if_and\
  166.       < void\
  167.       , container_detail::is_not_pair<T>\
  168.       , container_detail::not_<uses_allocator<T, ArgAlloc> >\
  169.       >::type\
  170.       dispatch_uses_allocator\
  171.       (ConstructAlloc &construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  172.    {\
  173.       (void)arg_alloc;\
  174.       allocator_traits<ConstructAlloc>::construct(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  175.    }\
  176. //
  177. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
  178. #undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
  179.  
  180. #define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
  181.    template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  182.    inline typename container_detail::enable_if_and\
  183.       < void\
  184.       , container_detail::is_not_pair<T>\
  185.       , uses_allocator<T, ArgAlloc>\
  186.       , is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
  187.       >::type\
  188.       dispatch_uses_allocator\
  189.       (ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  190.    {\
  191.       allocator_traits<ConstructAlloc>::construct\
  192.          (construct_alloc, p, allocator_arg, ::mars_boost::forward<ArgAlloc>(arg_alloc) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
  193.    }\
  194. //
  195. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
  196. #undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
  197.  
  198. #define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
  199.    template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
  200.    inline typename container_detail::enable_if_and\
  201.       < void\
  202.       , container_detail::is_not_pair<T>\
  203.       , uses_allocator<T, ArgAlloc>\
  204.       , container_detail::not_<is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
  205.       >::type\
  206.       dispatch_uses_allocator\
  207.       (ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
  208.    {\
  209.       allocator_traits<ConstructAlloc>::construct\
  210.          (construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N, ::mars_boost::forward<ArgAlloc>(arg_alloc));\
  211.    }\
  212. //
  213. BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
  214. #undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
  215.  
  216. #endif   //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  217.  
  218. template < typename ConstructAlloc
  219.          , typename ArgAlloc
  220.          , typename Pair
  221.          > inline
  222. BOOST_CONTAINER_DOC1ST(void, typename container_detail::enable_if<container_detail::is_pair<Pair> >::type)
  223.    dispatch_uses_allocator
  224.    ( ConstructAlloc & construct_alloc
  225.    , ArgAlloc & arg_alloc
  226.    , Pair* p)
  227. {
  228.    (dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->first));
  229.    BOOST_TRY{
  230.       (dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->second));
  231.    }
  232.    BOOST_CATCH(...) {
  233.       allocator_traits<ConstructAlloc>::destroy(construct_alloc, container_detail::addressof(p->first));
  234.       BOOST_RETHROW
  235.    }
  236.    BOOST_CATCH_END
  237. }
  238.  
  239.  
  240. template < typename ConstructAlloc
  241.          , typename ArgAlloc
  242.          , class Pair, class U, class V>
  243. BOOST_CONTAINER_DOC1ST(void, typename container_detail::enable_if<container_detail::is_pair<Pair> >::type)
  244.    dispatch_uses_allocator
  245.    ( ConstructAlloc & construct_alloc
  246.    , ArgAlloc & arg_alloc
  247.    , Pair* p, BOOST_FWD_REF(U) x, BOOST_FWD_REF(V) y)
  248. {
  249.    (dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->first), ::mars_boost::forward<U>(x));
  250.    BOOST_TRY{
  251.       (dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->second), ::mars_boost::forward<V>(y));
  252.    }
  253.    BOOST_CATCH(...){
  254.       allocator_traits<ConstructAlloc>::destroy(construct_alloc, container_detail::addressof(p->first));
  255.       BOOST_RETHROW
  256.    }
  257.    BOOST_CATCH_END
  258. }
  259.  
  260. template < typename ConstructAlloc
  261.          , typename ArgAlloc
  262.          , class Pair, class Pair2>
  263. BOOST_CONTAINER_DOC1ST(void, typename container_detail::enable_if< container_detail::is_pair<Pair> >::type)
  264.    dispatch_uses_allocator
  265.    (ConstructAlloc & construct_alloc
  266.    , ArgAlloc & arg_alloc
  267.    , Pair* p, Pair2& x)
  268. {  (dispatch_uses_allocator)(construct_alloc, arg_alloc, p, x.first, x.second);  }
  269.  
  270. template < typename ConstructAlloc
  271.          , typename ArgAlloc
  272.          , class Pair, class Pair2>
  273. typename container_detail::enable_if_and
  274.    < void
  275.    , container_detail::is_pair<Pair>
  276.    , container_detail::not_<mars_boost::move_detail::is_reference<Pair2> > >::type //This is needed for MSVC10 and ambiguous overloads
  277.    dispatch_uses_allocator
  278.    (ConstructAlloc & construct_alloc
  279.       , ArgAlloc & arg_alloc
  280.       , Pair* p, BOOST_RV_REF_BEG Pair2 BOOST_RV_REF_END x)
  281. {  (dispatch_uses_allocator)(construct_alloc, arg_alloc, p, ::mars_boost::move(x.first), ::mars_boost::move(x.second));  }
  282.  
  283. //template <typename ConstructAlloc, typename ArgAlloc, class Pair, class Pair2>
  284. //void dispatch_uses_allocator( ConstructAlloc & construct_alloc, ArgAlloc & arg_alloc
  285. //                            , pair<T1, T2>* p, piecewise_construct_t, tuple<Args1...> x, tuple<Args2...> y);
  286.  
  287. }  //namespace container_detail
  288.  
  289. }} // namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace container {
  290.  
  291. #include <boost/container/detail/config_end.hpp>
  292.  
  293. #endif //  BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
  294.  
downloaddispatch_uses_allocator.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top