Squashed 'third_party/boostorg/lexical_cast/' content from commit 5bfe667
Change-Id: I518d0a0b83082059176813a98b80ad92892ac745
git-subtree-dir: third_party/boostorg/lexical_cast
git-subtree-split: 5bfe6672d467ebd8de5d911c07b2a931b43156de
diff --git a/example/args_to_numbers.cpp b/example/args_to_numbers.cpp
new file mode 100644
index 0000000..edcc779
--- /dev/null
+++ b/example/args_to_numbers.cpp
@@ -0,0 +1,35 @@
+// Copyright 2013 Antony Polukhin
+
+// Distributed under the Boost Software License, Version 1.0.
+// (See the accompanying file LICENSE_1_0.txt
+// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
+
+//[lexical_cast_args_example
+//`The following example treats command line arguments as a sequence of numeric data
+
+#include <boost/lexical_cast.hpp>
+#include <vector>
+
+int main(int /*argc*/, char * argv[])
+{
+ using boost::lexical_cast;
+ using boost::bad_lexical_cast;
+
+ std::vector<short> args;
+
+ while (*++argv)
+ {
+ try
+ {
+ args.push_back(lexical_cast<short>(*argv));
+ }
+ catch(const bad_lexical_cast &)
+ {
+ args.push_back(0);
+ }
+ }
+
+ // ...
+}
+
+//] [/lexical_cast_args_example]