Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
CanCast is a checking code snippet that let you check if you can convert a std::string to another data type when using LexicalCast.
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. Below the code, a comparison between the two is shown.
#include <string> |
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.
This page has been created by the tool CodeToHtml