summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/lexical.h
blob: fc3879961d67e8572827ae538ceb46a7b079cc42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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