Commit c5ca1b76 authored by Davis King's avatar Davis King

Added a reference_wrapper implementation and modified the thread_function

slightly so it works with it.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403709
parent b8aa8b2f
// Copyright (C) 2010 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_REFERENCE_WRAPpER_H_
#define DLIB_REFERENCE_WRAPpER_H_
namespace dlib
{
// ----------------------------------------------------------------------------------------
template<
typename T
>
class reference_wrapper
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple object that just contains a reference to another object.
It is useful because it can serve as a kind of "copyable reference".
!*/
public:
typedef T type;
explicit reference_wrapper(T& o) : obj(&o) {}
operator T&() const { return *obj; }
T& get() const { return *obj; }
private:
T* obj;
};
// ----------------------------------------------------------------------------------------
template <typename T>
reference_wrapper<T> ref(
T& obj
) { return reference_wrapper<T>(obj); }
/*!
ensures
- returns a reference_wrapper that contains a reference to obj.
!*/
// ----------------------------------------------------------------------------------------
template <typename T>
reference_wrapper<T> ref(
reference_wrapper<T> obj
) { return obj; }
/*!
ensures
- returns the given reference_wrapper object without modification
!*/
// ----------------------------------------------------------------------------------------
template <typename T>
reference_wrapper<const T> cref(
const T& obj
) { return reference_wrapper<const T>(obj); }
/*!
ensures
- returns a reference_wrapper that contains a constant reference to obj.
!*/
// ----------------------------------------------------------------------------------------
template <typename T>
reference_wrapper<const T> cref(
reference_wrapper<T> obj
) { return cref(obj.get()); }
/*!
ensures
- converts the given reference_wrapper into a reference_wrapper that contains a
constant reference.
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_REFERENCE_WRAPpER_H_
......@@ -28,89 +28,86 @@ namespace dlib
class super_funct_4 : public base_funct
{
public:
super_funct_4 ( F funct, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
super_funct_4 ( F funct, T1 arg1, T2 arg2, T3 arg3, T4 arg4) :
f(funct),
a1(arg1),
a2(arg2),
a3(arg3),
a4(arg4)
{
a1 = arg1;
a2 = arg2;
a3 = arg3;
a4 = arg4;
f = funct;
}
void go() { f(a1, a2, a3, a4); }
F f;
T1 a1;
T2 a2;
T3 a3;
T4 a4;
F f;
};
template <typename F, typename T1, typename T2, typename T3>
class super_funct_3 : public base_funct
{
public:
super_funct_3 ( F funct, T1 arg1, T2 arg2, T3 arg3)
super_funct_3 ( F funct, T1 arg1, T2 arg2, T3 arg3):
f(funct),
a1(arg1),
a2(arg2),
a3(arg3)
{
a1 = arg1;
a2 = arg2;
a3 = arg3;
f = funct;
}
void go() { f(a1, a2, a3); }
F f;
T1 a1;
T2 a2;
T3 a3;
F f;
};
template <typename F, typename T1, typename T2>
class super_funct_2 : public base_funct
{
public:
super_funct_2 ( F funct, T1 arg1, T2 arg2)
super_funct_2 ( F funct, T1 arg1, T2 arg2) :
f(funct),
a1(arg1),
a2(arg2)
{
a1 = arg1;
a2 = arg2;
f = funct;
}
void go() { f(a1, a2); }
F f;
T1 a1;
T2 a2;
F f;
};
template <typename F, typename T>
class super_funct_1 : public base_funct
{
public:
super_funct_1 ( F funct, T arg)
super_funct_1 ( F funct, T arg) : f(funct), a(arg)
{
a = arg;
f = funct;
}
void go() { f(a); }
T a;
F f;
T a;
};
template <typename F>
class super_funct_0 : public base_funct
{
public:
super_funct_0 ( F funct)
super_funct_0 ( F funct) : f(funct)
{
f = funct;
}
void go() { f(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment