Skip to content

Commit

Permalink
#188 Provide polyfill for std::to_string for c++98 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-ogre committed Dec 5, 2024
1 parent 46f1ce1 commit a3e9620
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 18 additions & 3 deletions CDT/include/CDTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ typedef char couldnt_parse_cxx_standard[-1]; ///< Error: couldn't parse standard

#include <array>
#include <functional>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

namespace CDT
{
using std::array;
using std::get;
using std::make_tuple;
using std::tie;
using std::to_string;
using std::tuple;
using std::unordered_map;
using std::unordered_set;
Expand All @@ -72,6 +75,7 @@ using std::unordered_set;
#else
#include <boost/array.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
Expand All @@ -84,12 +88,17 @@ using boost::tie;
using boost::tuple;
using boost::unordered_map;
using boost::unordered_set;

template <typename T>
std::string to_string(const T& value)
{
return boost::lexical_cast<std::string>(value);
}
} // namespace CDT
#endif

namespace CDT
{

/// 2D vector
template <typename T>
struct CDT_EXPORT V2d
Expand Down Expand Up @@ -168,6 +177,7 @@ struct CDT_EXPORT Box2d
{
envelopPoint(p.x, p.y);
}

/// Envelop box around a point with given coordinates
void envelopPoint(const T x, const T y)
{
Expand Down Expand Up @@ -209,14 +219,19 @@ struct CDT_EXPORT Edge
{
/// Constructor
Edge(VertInd iV1, VertInd iV2);

/// Equals operator
bool operator==(const Edge& other) const;

/// Not-equals operator
bool operator!=(const Edge& other) const;

/// V1 getter
VertInd v1() const;

/// V2 getter
VertInd v2() const;

/// Edges' vertices
const std::pair<VertInd, VertInd>& verts() const;

Expand Down Expand Up @@ -287,6 +302,7 @@ struct CDT_EXPORT Triangle
}
return std::make_pair(neighbors[2], vertices[0]);
}

/// Previous triangle adjacent to a vertex (counter-clockwise)
/// @returns pair of previous triangle and the other vertex of a common edge
std::pair<TriInd, VertInd> prev(const VertInd i) const
Expand Down Expand Up @@ -428,7 +444,6 @@ CDT_EXPORT T distanceSquared(const V2d<T>& a, const V2d<T>& b);

/// Check if any of triangle's vertices belongs to a super-triangle
CDT_INLINE_IF_HEADER_ONLY bool touchesSuperTriangle(const Triangle& t);

} // namespace CDT

#ifndef CDT_USE_AS_COMPILED_LIBRARY
Expand All @@ -444,7 +459,6 @@ namespace std
namespace boost
#endif
{

#ifdef CDT_USE_STRONG_TYPING

/// Vertex index hasher
Expand Down Expand Up @@ -491,6 +505,7 @@ struct hash<CDT::Edge>
#endif
seed ^= Hasher()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

static std::size_t hashEdge(const CDT::Edge& e)
{
const std::pair<CDT::VertInd, CDT::VertInd>& vv = e.verts();
Expand Down
12 changes: 6 additions & 6 deletions CDT/include/Triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Error : public std::runtime_error
Error(const std::string& description, const SourceLocation& srcLoc)
: std::runtime_error(
description + "\nin '" + srcLoc.func() + "' at " + srcLoc.file() +
":" + std::to_string(srcLoc.line()))
":" + CDT::to_string(srcLoc.line()))
, m_description(description)
, m_srcLoc(srcLoc)
{}
Expand Down Expand Up @@ -188,8 +188,8 @@ class DuplicateVertexError : public Error
const VertInd v2,
const SourceLocation& srcLoc)
: Error(
"Duplicate vertex detected: #" + std::to_string(v1) +
" is a duplicate of #" + std::to_string(v2),
"Duplicate vertex detected: #" + CDT::to_string(v1) +
" is a duplicate of #" + CDT::to_string(v2),
srcLoc)
, m_v1(v1)
, m_v2(v2)
Expand Down Expand Up @@ -220,9 +220,9 @@ class IntersectingConstraintsError : public Error
const SourceLocation& srcLoc)
: Error(
"Intersecting constraint edges detected: (" +
std::to_string(e1.v1()) + ", " + std::to_string(e1.v2()) +
") intersects (" + std::to_string(e2.v1()) + ", " +
std::to_string(e2.v2()) + ")",
CDT::to_string(e1.v1()) + ", " + CDT::to_string(e1.v2()) +
") intersects (" + CDT::to_string(e2.v1()) + ", " +
CDT::to_string(e2.v2()) + ")",
srcLoc)
, m_e1(e1)
, m_e2(e2)
Expand Down

0 comments on commit a3e9620

Please sign in to comment.