From: "Terje Slettebø"
From: "Yuval Ronen"
1. lexical_cast(Source arg) takes the source argument by value. Why not by const& ? Calling lexical_cast(some_basic_string) now makes a copy of the source argument for no reason.
template
Target lexical_cast(const Source &arg) { // Array-to-pointer decay typedef typename mpl::if_< is_array<Source>, add_pointer
::type>::type, Source >::type NewSource; detail::lexical_stream
interpreter; Target result; if(!(interpreter << arg && interpreter >> result)) throw_exception(bad_lexical_cast(typeid(NewSource), typeid(Target))); return result; }
The additional includes are:
#include
#include #include #include #include
Come to think of it, it can be done simpler and clearer, and avoiding any
extra includes, like this:
namespace detail
{
template<class T>
struct array_to_pointer_decay
{
typedef T type;
};
template