1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_UTILITY_DIM_HPP
12 #define BOOST_COMPUTE_UTILITY_DIM_HPP
14 #include <boost/compute/config.hpp>
15 #include <boost/compute/utility/extents.hpp>
20 #ifndef BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
21 /// The variadic \c dim() function provides a concise syntax for creating
22 /// \ref extents objects.
26 /// extents<2> region = dim(640, 480); // region == (640, 480)
29 /// \see \ref extents "extents<N>"
30 template<class... Args>
31 inline extents<sizeof...(Args)> dim(Args... args)
33 return extents<sizeof...(Args)>({ static_cast<size_t>(args)... });
36 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
37 // for some inexplicable reason passing one parameter to 'dim' variadic template
38 // generates compile error on msvc 2013 update 4
40 inline extents<1> dim(T arg)
42 return extents<1>(static_cast<size_t>(arg));
44 #endif // BOOST_WORKAROUND(BOOST_MSVC, <= 1800)
47 // dim() function definitions for non-c++11 compilers
48 #define BOOST_COMPUTE_DETAIL_ASSIGN_DIM(z, n, var) \
49 var[n] = BOOST_PP_CAT(e, n);
51 #define BOOST_COMPUTE_DETAIL_DEFINE_DIM(z, n, var) \
52 inline extents<n> dim(BOOST_PP_ENUM_PARAMS(n, size_t e)) \
55 BOOST_PP_REPEAT(n, BOOST_COMPUTE_DETAIL_ASSIGN_DIM, exts) \
59 BOOST_PP_REPEAT(BOOST_COMPUTE_MAX_ARITY, BOOST_COMPUTE_DETAIL_DEFINE_DIM, ~)
61 #undef BOOST_COMPUTE_DETAIL_ASSIGN_DIM
62 #undef BOOST_COMPUTE_DETAIL_DEFINE_DIM
64 #endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
68 inline extents<N> dim()
73 } // end compute namespace
74 } // end boost namespace
76 #endif // BOOST_COMPUTE_UTILITY_DIM_HPP