Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:00

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP
0012 #define BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP
0013 
0014 #include <string>
0015 
0016 namespace boost {
0017 namespace compute {
0018 namespace detail {
0019 
0020 template<class T, class Arg>
0021 struct invoked_field
0022 {
0023     typedef T result_type;
0024 
0025     invoked_field(const Arg &arg, const std::string &field)
0026         : m_arg(arg),
0027           m_field(field)
0028     {
0029     }
0030 
0031     Arg m_arg;
0032     std::string m_field;
0033 };
0034 
0035 } // end detail namespace
0036 
0037 /// Returns the named field from a value.
0038 ///
0039 /// The template-type \c T specifies the field's value type. Note
0040 /// that the value type must match the actual type of the field
0041 /// otherwise runtime compilation or logic errors may occur.
0042 ///
0043 /// For example, to access the \c second field in a
0044 /// \c std::pair<int, float> object:
0045 /// \code
0046 /// field<float>("second");
0047 /// \endcode
0048 ///
0049 /// This can also be used with vector types to access individual
0050 /// components as well as perform swizzle operations.
0051 ///
0052 /// For example, to access the first and third components of an
0053 /// \c int vector type (e.g. \c int4):
0054 /// \code
0055 /// field<int2_>("xz");
0056 /// \endcode
0057 ///
0058 /// \see \ref get "get<N>"
0059 template<class T>
0060 class field
0061 {
0062 public:
0063     /// Result type.
0064     typedef T result_type;
0065 
0066     /// Creates a new field functor with \p field.
0067     field(const std::string &field)
0068         : m_field(field)
0069     {
0070     }
0071 
0072     /// \internal_
0073     template<class Arg>
0074     detail::invoked_field<T, Arg> operator()(const Arg &arg) const
0075     {
0076         return detail::invoked_field<T, Arg>(arg, m_field);
0077     }
0078 
0079 private:
0080     std::string m_field;
0081 };
0082 
0083 } // end compute namespace
0084 } // end boost namespace
0085 
0086 #endif // BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP