-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLexicalCast.h
More file actions
29 lines (24 loc) · 802 Bytes
/
LexicalCast.h
File metadata and controls
29 lines (24 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2014-2015 Isis Innovation Limited and the authors of InfiniTAM
#pragma once
#include <sstream>
namespace ORUtils
{
/**
* \brief Performs a lexical conversion from the source type to the target type.
*
* This is a lightweight replacement for boost::lexical_cast. It's not as
* sophisticated as that, but it works well enough. Note that we can't use
* exceptions, since they're not well supported on Android.
*
* \param src The source value to convert.
* \param target A location into which to store the converted value.
* \return true, if the conversion succeeded, or false otherwise.
*/
template <typename Target, typename Source>
bool lexical_cast(const Source& src, Target& target)
{
std::stringstream ss;
ss << src;
return ss >> target && ss.eof();
}
}