From 9110c896c5201eabe7f84925a3efe0ab5e48bd05 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Sun, 24 Nov 2019 23:11:58 +0800 Subject: [PATCH] Further simplify the C++ error info stack (#21093) (#21304) * simplify C++ error stack by rewrite Place, test=develop * polish assignment overload func, test=develop --- paddle/fluid/platform/place.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/platform/place.h b/paddle/fluid/platform/place.h index daa70e943de..4e7e157e3e2 100644 --- a/paddle/fluid/platform/place.h +++ b/paddle/fluid/platform/place.h @@ -76,7 +76,24 @@ struct IsCUDAPinnedPlace : public boost::static_visitor { bool operator()(const CUDAPinnedPlace &cuda_pinned) const { return true; } }; -typedef boost::variant Place; +class Place : public boost::variant { + private: + using PlaceBase = boost::variant; + + public: + Place() = default; + Place(const CPUPlace &cpu_place) : PlaceBase(cpu_place) {} // NOLINT + Place(const CUDAPlace &cuda_place) : PlaceBase(cuda_place) {} // NOLINT + Place(const CUDAPinnedPlace &cuda_pinned_place) // NOLINT + : PlaceBase(cuda_pinned_place) {} + + bool operator<(const Place &place) const { + return PlaceBase::operator<(static_cast(place)); + } + bool operator==(const Place &place) const { + return PlaceBase::operator==(static_cast(place)); + } +}; using PlaceList = std::vector; -- GitLab