dune-spgrid  2.7
misc.hh
Go to the documentation of this file.
1 #ifndef DUNE_SPGRID_MISC_HH
2 #define DUNE_SPGRID_MISC_HH
3 
4 #include <utility>
5 #include <vector>
6 
12 namespace Dune
13 {
14 
22  template< class T, class Op >
23  inline std::vector< decltype( std::declval< Op >()( std::declval< T >() ) ) >
24  transform ( const std::vector< T > &in, Op op )
25  {
26  const std::size_t size = in.size();
27  std::vector< T > out;
28  out.reserve( size );
29  for( const T &v : in )
30  out.push_back( op( v ) );
31  return std::move( out );
32  }
33 
34 } // namespace Dune
35 
36 #endif // #ifndef DUNE_SPGRID_MISC_HH
Definition: iostream.hh:7
std::vector< decltype(std::declval< Op >)(std::declval< T >))) > transform(const std::vector< T > &in, Op op)
copy a vector, performing an operation on each element
Definition: misc.hh:24