Utils.h (11555:2efa95cf8504) | Utils.h (12392:e0dbdf30a2a5) |
---|---|
1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are --- 32 unchanged lines hidden (view full) --- 41#include <string> 42#include <sstream> 43#include <stdexcept> 44 45 46template<typename T> 47T fromString(const std::string& s, 48 std::ios_base& (*f)(std::ios_base &) = std::dec) | 1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are --- 32 unchanged lines hidden (view full) --- 41#include <string> 42#include <sstream> 43#include <stdexcept> 44 45 46template<typename T> 47T fromString(const std::string& s, 48 std::ios_base& (*f)(std::ios_base &) = std::dec) |
49throw(std::runtime_error) | |
50{ 51 std::istringstream is(s); 52 T t; 53 54 if (!(is >> f >> t)) { 55 throw std::runtime_error("Cannot convert string"); 56 } 57 58 return t; 59} 60 61#endif /* UTILS_H */ | 49{ 50 std::istringstream is(s); 51 T t; 52 53 if (!(is >> f >> t)) { 54 throw std::runtime_error("Cannot convert string"); 55 } 56 57 return t; 58} 59 60#endif /* UTILS_H */ |