Commit 6b34d376 authored by Davis King's avatar Davis King

Added the string_assign tool

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403876
parent 9181bfd8
......@@ -336,6 +336,36 @@ namespace dlib
template <typename T>
inline const T string_cast (const wchar_t* str){ return string_cast<T>(std::wstring(str)); }
// ----------------------------------------------------------------------------------------
class string_assign
{
class string_assign_helper
{
public:
string_assign_helper (const std::string& str_) : str(str_) {}
template <typename T>
operator T () const
{
return string_cast<T>(str);
}
private:
const std::string& str;
};
public:
string_assign_helper operator=(
const std::string& str
) const
{
return string_assign_helper(str);
}
};
// ----------------------------------------------------------------------------------------
template <
......
......@@ -38,6 +38,29 @@ namespace dlib
str into a T. Also, string_cast_error::info == str
!*/
// ----------------------------------------------------------------------------------------
class string_assign
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple tool which provides an alternative syntax for using
the string_cast() function. It can be understood by considering
the following example:
string_assign sa;
int val;
double dval;
val = sa = "1234"; // executes: val = string_cast<int>("1234");
dval = sa = "3.141"; // executes: val = string_cast<double>("3.141");
After executing, val will be equal to 1234 and dval will be 3.141.
Note that you can use string_assign to assign to any type which you could
use with string_cast(). You aren't just limited to ints and doubles.
!*/
};
// ----------------------------------------------------------------------------------------
class cast_to_string_error : public error
......
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