// (C) Copyright Gennadiy Rozental 2001. // 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) // See http://www.boost.org/libs/test for the library home page. // ///@file ///Defines monomorphic dataset based on C++11 initializer_list template // *************************************************************************** #ifndef BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER #define BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER // Boost.Test #include #include #include #include #include //____________________________________________________________________________// namespace boost { namespace unit_test { namespace data { namespace monomorphic { // ************************************************************************** // // ************** initializer_list ************** // // ************************************************************************** // /// Dataset view from an initializer_list or variadic template arguments /// /// The data should be stored in the dataset, and since the elements /// are passed by an @c std::initializer_list , it implies a copy of /// the elements. template class init_list { public: enum { arity = 1 }; typedef typename std::vector::const_iterator iterator; //! Constructor copies content of initializer_list init_list( std::initializer_list il ) : m_data( il ) {} #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ !defined(BOOST_TEST_ERRONEOUS_INIT_LIST) //! Variadic template initialization template init_list( Args&& ... args ) { int dummy[] = { 0, (m_data.emplace_back(std::forward(args)), 0)... }; boost::ignore_unused(dummy); } #endif //! dataset interface data::size_t size() const { return m_data.size(); } iterator begin() const { return m_data.begin(); } private: // Data members std::vector m_data; }; //! Specialization of init_list for type bool template <> class init_list { public: typedef bool sample; enum { arity = 1 }; //! Constructor copies content of initializer_list init_list( std::initializer_list&& il ) : m_data( std::forward>( il ) ) {} #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ !defined(BOOST_TEST_ERRONEOUS_INIT_LIST) //! Variadic template initialization template init_list( Args&& ... args ) : m_data{ args... } { } #endif struct non_proxy_iterator { std::vector::const_iterator iterator; non_proxy_iterator(std::vector::const_iterator &&it) : iterator(std::forward::const_iterator>(it)) {} bool operator*() const { return *iterator; } non_proxy_iterator& operator++() { ++iterator; return *this; } }; typedef non_proxy_iterator iterator; //! dataset interface data::size_t size() const { return m_data.size(); } iterator begin() const { return m_data.begin(); } private: // Data members std::vector m_data; }; //____________________________________________________________________________// //! An array dataset is a dataset template struct is_dataset> : mpl::true_ {}; } // namespace monomorphic //____________________________________________________________________________// //! @overload boost::unit_test::data::make() template inline monomorphic::init_list make( std::initializer_list&& il ) { return monomorphic::init_list( std::forward>( il ) ); } #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \ !defined(BOOST_TEST_ERRONEOUS_INIT_LIST) template inline typename std::enable_if< !monomorphic::has_dataset::value, monomorphic::init_list >::type make( T&& arg0, Args&&... args ) { return monomorphic::init_list( std::forward(arg0), std::forward( args )... ); } #endif } // namespace data } // namespace unit_test } // namespace boost #include #endif // BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER