Changeset 2285


Ignore:
Timestamp:
Jun 27, 2010, 2:24:42 AM (11 years ago)
Author:
Peter
Message:

adding a class Dereferencer, a functor that returns *argument. refs #632

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility_test.cc

    r2274 r2285  
    6464void test_ptr_compare(test::Suite& suite);
    6565void test_compose_functors(test::Suite& suite);
     66void test_dereferencer(test::Suite& suite);
    6667
    6768int main(int argc, char* argv[])
     
    225226}
    226227
     228
     229void test_dereferencer(test::Suite& suite)
     230{
     231  using utility::Dereferencer;
     232  Dereferencer<double*> deref;
     233  double x = 0;
     234  double* px = &x;
     235  deref(px) = 1.662;
     236  if (!suite.add(x==1.662)) {
     237    suite.out() << "test_dereferencer failed: x: " << x << "\n";
     238  }
     239}
    227240
    228241
     
    495508
    496509}
     510
  • trunk/yat/utility/stl_utility.h

    r2275 r2285  
    4949#include <exception>
    5050#include <functional>
     51#include <iterator>
    5152#include <map>
    5253#include <ostream>
     
    8990    inline T operator()(T x) const
    9091    { return std::abs(x); }
     92  };
     93
     94
     95  /**
     96     \brief Adaptor between pointer and pointee interface
     97
     98     Pointer must have an \c operator*, i.e., \c Pointer can be a
     99     traditional pointer or an \input_iterator. Return type is decided
     100     by <a href=http://www.sgi.com/tech/stl/iterator_traits.html>
     101     std::iterator_traits </a>.
     102   */
     103  template<typename Pointer>
     104  struct Dereferencer :
     105    public std::unary_function<Pointer,
     106                               typename std::iterator_traits<Pointer>::reference>
     107  {
     108    /**
     109       \return * \a ti
     110     */
     111    typename std::iterator_traits<Pointer>::reference
     112    operator()(Pointer ti) const { return *ti; }
    91113  };
    92114
Note: See TracChangeset for help on using the changeset viewer.