Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
boost::bad_lexical_cast is a Boost exception thrown when boost::lexical_cast fails.
CanLexicalCast checks if a boost::lexical_cast will be successful, by catching a possible boost::bad_lexical_cast.
#include <cassert> |
The table below shows if a std::string can be converted according to CanCast (CC) and CanLexicalCast (CLC). Note that the first std::string was a space (' '). Below the table I show the code I've used to generate this output. CanCast serves the same purpose as CanLexicalCast, but does not throw an exception and does not use Boost. Note that there are differences between CanCast and CanLexicalCast, as CanLexicalCast is more strict.
Type | int | int | double | double |
string | CC | CLC | CC | CLC |
| false | false | false | false |
a | false | false | false | false |
1 | true | true | true | true |
1,1 | true | false | true | false |
1.1 | true | false | true | true |
1.1.1 | true | false | true | false |
-1 | true | true | true | true |
-1.1 | true | false | true | true |
-1.1.1 | true | false | true | false |
#include <vector> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.