From edd6680a7173b1cbb68d6ab3c8b56f3cde46ebd8 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Tue, 12 Nov 2019 09:11:48 +0800 Subject: [PATCH] Further simplify the C++ error info stack (#21093) * 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