1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 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_FUNCTIONAL_FIELD_HPP
12 #define BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP
20 template<class T, class Arg>
23 typedef T result_type;
25 invoked_field(const Arg &arg, const std::string &field)
35 } // end detail namespace
37 /// Returns the named field from a value.
39 /// The template-type \c T specifies the field's value type. Note
40 /// that the value type must match the actual type of the field
41 /// otherwise runtime compilation or logic errors may occur.
43 /// For example, to access the \c second field in a
44 /// \c std::pair<int, float> object:
46 /// field<float>("second");
49 /// This can also be used with vector types to access individual
50 /// components as well as perform swizzle operations.
52 /// For example, to access the first and third components of an
53 /// \c int vector type (e.g. \c int4):
55 /// field<int2_>("xz");
58 /// \see \ref get "get<N>"
64 typedef T result_type;
66 /// Creates a new field functor with \p field.
67 field(const std::string &field)
74 detail::invoked_field<T, Arg> operator()(const Arg &arg) const
76 return detail::invoked_field<T, Arg>(arg, m_field);
83 } // end compute namespace
84 } // end boost namespace
86 #endif // BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP