瀏覽代碼

bugfix: fix ambiguity in Object::operator T
bugfix: return const-ref from Context
refactor: add Context::has to avoid try-catch checks

Sam Jaffe 2 年之前
父節點
當前提交
c348302210
共有 2 個文件被更改,包括 4 次插入3 次删除
  1. 2 1
      include/reflection/context.h
  2. 2 2
      include/reflection/object.h

+ 2 - 1
include/reflection/context.h

@@ -26,7 +26,8 @@ public:
 public:
   explicit Context(std::initializer_list<Arg> data) : data_(data.begin(), data.end()) {}
 
-  Object get(std::string_view id) const { return data_.at(id); }
+  Object const & get(std::string_view id) const { return data_.at(id); }
+  bool has(std::string_view id) const { return data_.count(id); }
 
   template <typename C,
             typename = std::enable_if_t<std::is_constructible_v<

+ 2 - 2
include/reflection/object.h

@@ -34,8 +34,8 @@ public:
 
   template <typename T> bool is_a() const { return type_ == typeid(T); }
 
-  template <typename T> operator T &() const & { return cast<T &>(); }
-  template <typename T> operator T const &() const & {
+  template <typename T> explicit operator T &() const & { return cast<T &>(); }
+  template <typename T> explicit operator T const &() const & {
     return cast<T const &>();
   }
   template <typename T> operator T() const & { return cast<T>(); }