summaryrefslogtreecommitdiff
path: root/graphics/asymptote/lexical.h
blob: 89f3edb37ab75de77a6c72cf90b88962502fec54 (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