Commit 3a24b2d3 authored by Fawzi Mohamed's avatar Fawzi Mohamed Committed by hjk
Browse files

utils/function: expose also ref and cref



ref and cref are also in tr1, and in functional, and are useful when
when using functors allocated on the stack that should not be copied.

Change-Id: I7e14560d88eaa9306e47c4bd71d011f406d1054a
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 7af8af01
......@@ -41,7 +41,7 @@ void functionUser(Utils::function<int()> generator, Utils::function<void(int)> c
struct GenFunctor
{
int operator()() { return 29; }
int operator()() const { return 29; }
};
struct ConsumerFunctor
......@@ -49,6 +49,13 @@ struct ConsumerFunctor
void operator()(int) {}
};
struct ConsumerFunctor2
{
ConsumerFunctor2() : i(0) { }
int i;
void operator()(int j) { i = j; }
};
int generatorF()
{
return 42;
......@@ -64,6 +71,9 @@ void test()
{
functionUser(GenFunctor(), ConsumerFunctor());
functionUser(&generatorF, &consumerF);
ConsumerFunctor2 f2;
GenFunctor g2;
functionUser(Utils::cref(g2), Utils::ref(f2));
}
} // end namespace
......@@ -39,9 +39,9 @@
# ifdef __GNUC__
# include <tr1/functional>
# endif
namespace Utils { using std::tr1::function; }
namespace Utils { using std::tr1::function; using std::tr1::ref; using std::tr1::cref; }
#else
namespace Utils { using std::function; }
namespace Utils { using std::function; using std::ref; using std::cref; }
#endif
#endif // QTC_FUNCTION_H
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