BVB Source Codes

mars Show wrap_unwrap.hpp Source code

Return Download mars: download wrap_unwrap.hpp Source code - Download mars Source code - Type:.hpp
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2003-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5.  
  6. // See http://www.boost.org/libs/iostreams for documentation.
  7.  
  8. #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
  9. #define BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
  10.  
  11. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  12. # pragma once
  13. #endif              
  14.  
  15. #include <boost/config.hpp>                             // SFINAE, MSVC.
  16. #include <boost/detail/workaround.hpp>
  17. #include <boost/iostreams/detail/enable_if_stream.hpp>
  18. #include <boost/iostreams/traits_fwd.hpp>               // is_std_io.
  19. #include <boost/mpl/bool.hpp>
  20. #include <boost/mpl/identity.hpp>
  21. #include <boost/mpl/eval_if.hpp>
  22. #include <boost/mpl/if.hpp>
  23. #include <boost/ref.hpp>
  24.  
  25. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace iostreams { namespace detail {
  26.                    
  27. //------------------Definition of wrap/unwrap traits--------------------------//
  28.  
  29. template<typename T>
  30. struct wrapped_type
  31.     : mpl::if_<is_std_io<T>, reference_wrapper<T>, T>
  32.     { };
  33.  
  34. template<typename T>
  35. struct unwrapped_type
  36.     : unwrap_reference<T>
  37.     { };
  38.  
  39. template<typename T>
  40. struct unwrap_ios
  41.     : mpl::eval_if<
  42.           is_std_io<T>,
  43.           unwrap_reference<T>,
  44.           mpl::identity<T>
  45.       >
  46.     { };
  47.  
  48. //------------------Definition of wrap----------------------------------------//
  49.  
  50. #ifndef BOOST_NO_SFINAE //----------------------------------------------------//
  51.     template<typename T>
  52.     inline T wrap(const T& t BOOST_IOSTREAMS_DISABLE_IF_STREAM(T))
  53.     { return t; }
  54.  
  55.     template<typename T>
  56.     inline typename wrapped_type<T>::type
  57.     wrap(T& t BOOST_IOSTREAMS_ENABLE_IF_STREAM(T)) { return mars_boost::ref(t); }
  58. #else // #ifndef BOOST_NO_SFINAE //-------------------------------------------//
  59.     template<typename T>
  60.     inline typename wrapped_type<T>::type // BCC 5.x needs namespace qualification.
  61.     wrap_impl(const T& t, mpl::true_) { return mars_boost::ref(const_cast<T&>(t)); }
  62.  
  63.     template<typename T>
  64.     inline typename wrapped_type<T>::type // BCC 5.x needs namespace qualification.
  65.     wrap_impl(T& t, mpl::true_) { return mars_boost::ref(t); }
  66.  
  67.     template<typename T>
  68.     inline typename wrapped_type<T>::type
  69.     wrap_impl(const T& t, mpl::false_) { return t; }
  70.  
  71.     template<typename T>
  72.     inline typename wrapped_type<T>::type
  73.     wrap_impl(T& t, mpl::false_) { return t; }
  74.  
  75.     template<typename T>
  76.     inline typename wrapped_type<T>::type
  77.     wrap(const T& t) { return wrap_impl(t, is_std_io<T>()); }
  78.  
  79.     template<typename T>
  80.     inline typename wrapped_type<T>::type
  81.     wrap(T& t) { return wrap_impl(t, is_std_io<T>()); }
  82. #endif // #ifndef BOOST_NO_SFINAE //------------------------------------------//
  83.  
  84. //------------------Definition of unwrap--------------------------------------//
  85.  
  86. #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310) //----------------------------------//
  87.  
  88. template<typename T>
  89. typename unwrapped_type<T>::type&
  90. unwrap(const reference_wrapper<T>& ref) { return ref.get(); }
  91.  
  92. template<typename T>
  93. typename unwrapped_type<T>::type& unwrap(T& t) { return t; }
  94.  
  95. template<typename T>
  96. const typename unwrapped_type<T>::type& unwrap(const T& t) { return t; }
  97.  
  98. #else // #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310) //-------------------------//
  99.  
  100. // Since unwrap is a potential bottleneck, we avoid runtime tag dispatch.
  101. template<bool IsRefWrap>
  102. struct unwrap_impl;
  103.  
  104. template<>
  105. struct unwrap_impl<true> {
  106.     template<typename T>
  107.     static typename unwrapped_type<T>::type& unwrap(const T& t)
  108.     { return t.get(); }
  109. };
  110.  
  111. template<>
  112. struct unwrap_impl<false> {
  113.     template<typename T>
  114.     static typename unwrapped_type<T>::type& unwrap(const T& t)
  115.     { return const_cast<T&>(t); }
  116. };
  117.  
  118. template<typename T>
  119. typename unwrapped_type<T>::type&
  120. unwrap(const T& t)
  121. { return unwrap_impl<is_reference_wrapper<T>::value>::unwrap(t); }
  122.  
  123. #endif // #if !BOOST_WORKAROUND(BOOST_MSVC, < 1310) //------------------------//
  124.  
  125. } } } // End namespaces detail, iostreams, boost.
  126.  
  127. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_WRAP_UNWRAP_HPP_INCLUDED
  128.  
downloadwrap_unwrap.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