summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/lexical.h
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/utils/asymptote/lexical.h')
-rw-r--r--Build/source/utils/asymptote/lexical.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/Build/source/utils/asymptote/lexical.h b/Build/source/utils/asymptote/lexical.h
new file mode 100644
index 00000000000..89f3edb37ab
--- /dev/null
+++ b/Build/source/utils/asymptote/lexical.h
@@ -0,0 +1,23 @@
+#ifndef __lexical_h__
+#define __lexical_h__ 1
+
+#include <sstream>
+
+#include "common.h"
+
+namespace lexical {
+
+class bad_cast {};
+
+template <typename T>
+T cast(const string& s, bool tolerant=false)
+{
+ istringstream is(s);
+ T value;
+ if(is && is >> value && ((is >> std::ws).eof() || tolerant)) return value;
+ throw bad_cast();
+}
+
+}
+
+#endif