|
Boost : |
From: Markus Werle (numerical.simulation_at_[hidden])
Date: 2003-05-06 07:47:37
Hi!
The feature mentioned in the subject is missing in boost.
(actually it throws)
I propose adding something simmilar to the (incomplete) stuff below.
Any comments?
Markus
--- begin code ----
namespace boost {
namespace detail {
template <typename Target, typename Source>
class lexical_stream_common_stuff;
template <typename Source>
class lexical_stream_common_stuff<bool, Source>
{
public:
lexical_stream_common_stuff()
{}
template<typename InputStreamable>
bool operator>>(InputStreamable &output) const
{
return
!is_pointer<InputStreamable>::value &&
result_ >> output;
}
bool operator>>(bool &output) const
{
output = result_;
return true;
}
protected:
void set_result(bool b)
{
result_ = b;
}
bool assign_from(const std::string& s)
{
if ("true" == s)
{
result_ = true;
return true;
}
if ("false" == s)
{
result_ = false;
return true;
}
return false;
}
private:
bool result_;
};
template<>
class lexical_stream<bool, std::string>
: public lexical_stream_common_stuff<bool, std::string>
{
public:
lexical_stream()
{
std::cerr << "Hello\n";
}
~lexical_stream()
{
}
bool operator<<(const std::string &input)
{
return this->assign_from(input);
}
private:
bool result;
};
template<int N>
class lexical_stream<bool, char[N]>
: public lexical_stream_common_stuff<bool, char[N]>
{
public:
lexical_stream()
{
std::cerr << "Hello\n";
}
~lexical_stream()
{
}
bool operator<<(const char (&input)[N])
{
std::string input_s = std::string(input);
return this->assign_from(input_s);
}
};
template<>
class lexical_stream<bool, const char*>
: public lexical_stream_common_stuff<bool, const char*>
{
public:
lexical_stream()
{
std::cerr << "Hello\n";
}
~lexical_stream()
{
}
bool operator<<(const char * input)
{
std::string input_s = std::string(input);
return this->assign_from(input_s);
}
};
}
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk