~ubuntu-branches/debian/sid/libvcflib/sid

« back to all changes in this revision

Viewing changes to src/convert.h

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2016-09-16 15:52:29 UTC
  • Revision ID: package-import@ubuntu.com-20160916155229-24mxrntfylvsshsg
Tags: upstream-1.0.0~rc1+dfsg
ImportĀ upstreamĀ versionĀ 1.0.0~rc1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __CONVERT_H
 
2
#define __CONVERT_H
 
3
 
 
4
#include <sstream>
 
5
 
 
6
// converts the string into the specified type, setting r to the converted
 
7
// value and returning true/false on success or failure
 
8
template<typename T>
 
9
bool convert(const std::string& s, T& r) {
 
10
    std::istringstream iss(s);
 
11
    iss >> r;
 
12
    return iss.eof() ? true : false;
 
13
}
 
14
 
 
15
template<typename T>
 
16
std::string convert(const T& r) {
 
17
    std::ostringstream oss;
 
18
    oss << r;
 
19
    return oss.str();
 
20
}
 
21
 
 
22
#endif