added a static assert to check for const ref with use, added useRef keyword for these cases

This commit is contained in:
Peter Schojer 2008-05-13 13:41:08 +00:00
parent 92a0389b63
commit bad44e6e46

View File

@ -46,6 +46,7 @@
#include "Poco/Data/TypeHandler.h"
#include "Poco/SharedPtr.h"
#include "Poco/MetaProgramming.h"
#include "Poco/Bugcheck.h"
#include <vector>
#include <list>
#include <deque>
@ -1356,10 +1357,17 @@ template <typename T>
inline Binding<T>* use(T& t, const std::string& name = "")
/// Convenience function for a more compact Binding creation.
{
// if this test fails with an error, you tried to pass a const ref value to bind
// This check is here to avoid passing in local variables (like use(1) )
// Resolve this either by using bind (which will copy the value) or
// if you are sure that the const ref will still exist when execute is called (which can be a lot later!)
// then - and only then - use the "useRef" keyword instead
poco_static_assert (!IsConst<T>::VALUE);
return new Binding<T>(t, name, AbstractBinding::PD_IN);
}
inline Binding<NullData>* use(const NullData& t, const std::string& name = "")
/// NullData overload.
{
@ -1367,6 +1375,15 @@ inline Binding<NullData>* use(const NullData& t, const std::string& name = "")
}
template <typename T>
inline Binding<T>* useRef(T& t, const std::string& name = "")
/// Convenience function for a more compact Binding creation.
{
return new Binding<T>(t, name, AbstractBinding::PD_IN);
}
template <typename T>
inline Binding<T>* in(T& t, const std::string& name = "")
/// Convenience function for a more compact Binding creation.