~ubuntu-branches/debian/experimental/libtorrent/experimental

« back to all changes in this revision

Viewing changes to rak/functional.h

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-03-31 10:31:05 UTC
  • mto: (4.1.4 gutsy) (6.2.1 squeeze) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20070331103105-jzpp1rml6ud0ff75
Tags: upstream-0.11.4
ImportĀ upstreamĀ versionĀ 0.11.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
294
294
  return on_t<Src, Dest>(s, d);
295
295
}  
296
296
 
 
297
template <typename Src, typename Dest>
 
298
struct on2_t : public std::binary_function<typename Src::argument_type, typename Dest::second_argument_type, typename Dest::result_type> {
 
299
  typedef typename Dest::result_type result_type;
 
300
 
 
301
  on2_t(Src s, Dest d) : m_dest(d), m_src(s) {}
 
302
 
 
303
  result_type operator () (typename reference_fix<typename Src::argument_type>::type first, typename reference_fix<typename Dest::second_argument_type>::type second) {
 
304
    return m_dest(m_src(first), second);
 
305
  }
 
306
 
 
307
  Dest m_dest;
 
308
  Src m_src;
 
309
};
 
310
    
 
311
template <typename Src, typename Dest>
 
312
inline on2_t<Src, Dest>
 
313
on2(Src s, Dest d) {
 
314
  return on2_t<Src, Dest>(s, d);
 
315
}  
 
316
 
297
317
// Creates a functor for accessing a member.
298
318
template <typename Class, typename Member>
299
319
struct mem_ptr_t : public std::unary_function<Class*, Member&> {
462
482
  typedef Ret (Object::*Function)() const;
463
483
 
464
484
  const_mem_fun0() : m_object(NULL) {}
465
 
  const_mem_fun0(Object* o, Function f) : m_object(o), m_function(f) {}
 
485
  const_mem_fun0(const Object* o, Function f) : m_object(o), m_function(f) {}
466
486
 
467
487
  bool is_valid() const { return m_object; }
468
488
 
469
 
  Ret operator () () { return (m_object->*m_function)(); }
 
489
  Ret operator () () const { return (m_object->*m_function)(); }
470
490
  
471
491
private:
472
 
  Object* m_object;
473
 
  Function m_function;
 
492
  const Object* m_object;
 
493
  Function      m_function;
474
494
};
475
495
 
476
496
template <typename Object, typename Ret, typename Arg1>
498
518
  typedef Ret (Object::*Function)(Arg1) const;
499
519
 
500
520
  const_mem_fun1() : m_object(NULL) {}
501
 
  const_mem_fun1(Object* o, Function f) : m_object(o), m_function(f) {}
 
521
  const_mem_fun1(const Object* o, Function f) : m_object(o), m_function(f) {}
502
522
 
503
523
  bool is_valid() const { return m_object; }
504
524
 
505
 
  Ret operator () (Arg1 a1) { return (m_object->*m_function)(a1); }
 
525
  Ret operator () (Arg1 a1) const { return (m_object->*m_function)(a1); }
506
526
  
507
527
private:
508
 
  Object* m_object;
509
 
  Function m_function;
 
528
  const Object* m_object;
 
529
  Function      m_function;
510
530
};
511
531
 
512
532
template <typename Object, typename Ret, typename Arg1, typename Arg2>
557
577
 
558
578
template <typename Object, typename Ret>
559
579
inline const_mem_fun0<Object, Ret>
560
 
make_mem_fun(Object* o, Ret (Object::*f)() const) {
 
580
make_mem_fun(const Object* o, Ret (Object::*f)() const) {
561
581
 return const_mem_fun0<Object, Ret>(o, f);
562
582
}
563
583
 
569
589
 
570
590
template <typename Object, typename Ret, typename Arg1>
571
591
inline const_mem_fun1<Object, Ret, Arg1>
572
 
make_mem_fun(Object* o, Ret (Object::*f)(Arg1) const) {
 
592
make_mem_fun(const Object* o, Ret (Object::*f)(Arg1) const) {
573
593
 return const_mem_fun1<Object, Ret, Arg1>(o, f);
574
594
}
575
595