2
0
mirror of https://github.com/boostorg/compute.git synced 2026-02-19 14:22:12 +00:00

Add identity<T>() function

This commit is contained in:
Kyle Lutz
2014-11-28 14:08:59 -08:00
parent 85e03f7e69
commit 16fdb15395
5 changed files with 112 additions and 0 deletions

View File

@@ -1027,6 +1027,13 @@ inline meta_kernel& operator<<(meta_kernel &k,
return k << "convert_" << type_name<T>() << "(" << expr.m_arg << ")";
}
template<class T, class Arg>
inline meta_kernel& operator<<(meta_kernel &k,
const invoked_identity<T, Arg> &expr)
{
return k << expr.m_arg;
}
template<>
struct inject_type_impl<double_>
{

View File

@@ -23,6 +23,7 @@
#include <boost/compute/functional/geometry.hpp>
#include <boost/compute/functional/get.hpp>
#include <boost/compute/functional/hash.hpp>
#include <boost/compute/functional/identity.hpp>
#include <boost/compute/functional/integer.hpp>
#include <boost/compute/functional/logical.hpp>
#include <boost/compute/functional/math.hpp>

View File

@@ -0,0 +1,64 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
#define BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
namespace boost {
namespace compute {
namespace detail {
template<class T, class Arg>
struct invoked_identity
{
typedef T result_type;
invoked_identity(const Arg &arg)
: m_arg(arg)
{
}
Arg m_arg;
};
} // end detail namespace
/// Identity function which simply returns its input.
///
/// For example, to directly copy values using the transform() algorithm:
/// \code
/// transform(input.begin(), input.end(), output.begin(), identity<int>(), queue);
/// \endcode
///
/// \see as<T>(), convert<T>()
template<class T>
class identity
{
public:
/// Identity function result type.
typedef T result_type;
/// Creates a new identity function.
identity()
{
}
/// \internal_
template<class Arg>
detail::invoked_identity<T, Arg> operator()(const Arg &arg) const
{
return detail::invoked_identity<T, Arg>(arg);
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP