Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/test/data/monomorphic/initializer_list.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 ///@file
0009 ///Defines monomorphic dataset based on C++11 initializer_list template
0010 // ***************************************************************************
0011 
0012 #ifndef BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
0013 #define BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
0014 
0015 // Boost.Test
0016 #include <boost/test/data/config.hpp>
0017 #include <boost/test/data/monomorphic/fwd.hpp>
0018 
0019 #include <boost/core/ignore_unused.hpp>
0020 
0021 #include <vector>
0022 
0023 #include <boost/test/detail/suppress_warnings.hpp>
0024 
0025 //____________________________________________________________________________//
0026 
0027 namespace boost {
0028 namespace unit_test {
0029 namespace data {
0030 namespace monomorphic {
0031 
0032 // ************************************************************************** //
0033 // **************                initializer_list              ************** //
0034 // ************************************************************************** //
0035 
0036 /// Dataset view from an initializer_list or variadic template arguments
0037 ///
0038 /// The data should be stored in the dataset, and since the elements
0039 /// are passed by an @c std::initializer_list , it implies a copy of
0040 /// the elements.
0041 template<typename T>
0042 class init_list {
0043 public:
0044     static const int arity = 1;
0045 
0046     typedef typename std::vector<T>::const_iterator iterator;
0047 
0048     //! Constructor copies content of initializer_list
0049     init_list( std::initializer_list<T> il )
0050     : m_data( il )
0051     {}
0052   
0053 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
0054     !defined(BOOST_TEST_ERRONEOUS_INIT_LIST)
0055     //! Variadic template initialization
0056     template <class ...Args>
0057     init_list( Args&& ... args ) {
0058       int dummy[] = { 0, (m_data.emplace_back(std::forward<Args&&>(args)), 0)... };
0059       boost::ignore_unused(dummy);
0060     }
0061 #endif
0062 
0063     //! dataset interface
0064     data::size_t    size() const    { return m_data.size(); }
0065     iterator        begin() const   { return m_data.begin(); }
0066 
0067 private:
0068     // Data members
0069     std::vector<T> m_data;
0070 };
0071 
0072 //! Specialization of init_list for type bool
0073 template <>
0074 class init_list<bool> {
0075 public:
0076     typedef bool sample;
0077 
0078     static const int arity = 1;
0079 
0080     //! Constructor copies content of initializer_list
0081     init_list( std::initializer_list<bool>&& il )
0082     : m_data( std::forward<std::initializer_list<bool>>( il ) )
0083     {}
0084   
0085 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
0086     !defined(BOOST_TEST_ERRONEOUS_INIT_LIST)
0087     //! Variadic template initialization
0088     template <class ...Args>
0089     init_list( Args&& ... args ) : m_data{ args... }
0090     { }
0091 #endif
0092 
0093     struct non_proxy_iterator {
0094         std::vector<bool>::const_iterator iterator;
0095         non_proxy_iterator(std::vector<bool>::const_iterator &&it)
0096         : iterator(std::forward<std::vector<bool>::const_iterator>(it))
0097         {}
0098 
0099         bool operator*() const {
0100             return *iterator;
0101         }
0102 
0103         non_proxy_iterator& operator++() {
0104             ++iterator;
0105             return *this;
0106         }
0107     };
0108 
0109     typedef non_proxy_iterator iterator;
0110 
0111     //! dataset interface
0112     data::size_t    size() const    { return m_data.size(); }
0113     iterator        begin() const   { return m_data.begin(); }
0114 
0115 private:
0116     // Data members
0117     std::vector<bool> m_data;
0118 };
0119 
0120 //____________________________________________________________________________//
0121 
0122 //! An array dataset is a dataset
0123 template<typename T>
0124 struct is_dataset<init_list<T>> : mpl::true_ {};
0125 
0126 } // namespace monomorphic
0127 
0128 //____________________________________________________________________________//
0129 
0130 //! @overload boost::unit_test::data::make()
0131 template<typename T>
0132 inline monomorphic::init_list<T>
0133 make( std::initializer_list<T>&& il )
0134 {
0135     return monomorphic::init_list<T>( std::forward<std::initializer_list<T>>( il ) );
0136 }
0137 
0138 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
0139     !defined(BOOST_TEST_ERRONEOUS_INIT_LIST)
0140 template<class T, class ...Args>
0141 inline typename std::enable_if<
0142   !monomorphic::has_dataset<T, Args...>::value,
0143   monomorphic::init_list<T>
0144 >::type
0145 make( T&& arg0, Args&&... args )
0146 {
0147     return monomorphic::init_list<T>( std::forward<T>(arg0), std::forward<Args>( args )... );
0148 }
0149 #endif
0150 
0151 
0152 } // namespace data
0153 } // namespace unit_test
0154 } // namespace boost
0155 
0156 #include <boost/test/detail/enable_warnings.hpp>
0157 
0158 #endif // BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
0159