cpp-common: add `bt2s::optional`, alias of `nonstd::optional`
[babeltrace.git] / src / cpp-common / bt2 / field.hpp
index 241c17764b20ef4f3edca63410c16af49c91922b..69bf4ab6d916cc5f8378a397881b67accbe73bd9 100644 (file)
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
+#include "cpp-common/bt2s/optional.hpp"
 
 #include "borrowed-object.hpp"
 #include "field-class.hpp"
 #include "internal/utils.hpp"
+#include "raw-value-proxy.hpp"
 
 namespace bt2 {
 
@@ -102,8 +102,7 @@ protected:
     using _ThisCommonField = CommonField<LibObjT>;
 
 public:
-    using Class =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using Class = internal::DepFc<LibObjT>;
 
     explicit CommonField(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
@@ -115,12 +114,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonField& operator=(const CommonField<OtherLibObjT> val) noexcept
+    _ThisCommonField operator=(const CommonField<OtherLibObjT> val) noexcept
     {
         _ThisBorrowedObject::operator=(val);
         return *this;
     }
 
+    CommonField<const bt_field> asConst() const noexcept
+    {
+        return CommonField<const bt_field> {*this};
+    }
+
     FieldClassType classType() const noexcept
     {
         return static_cast<FieldClassType>(bt_field_get_class_type(this->libObjPtr()));
@@ -267,28 +271,32 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBoolField<LibObjT>& operator=(const CommonBoolField<OtherLibObjT> val) noexcept
+    CommonBoolField<LibObjT> operator=(const CommonBoolField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
-    CommonBoolField<LibObjT> operator=(const Value val) const noexcept
+    CommonBoolField<const bt_field> asConst() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return CommonBoolField<const bt_field> {*this};
+    }
 
-        bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val));
-        return *this;
+    RawValueProxy<CommonBoolField> operator*() const noexcept
+    {
+        return RawValueProxy<CommonBoolField> {*this};
     }
 
-    Value value() const noexcept
+    void value(const Value val) const noexcept
     {
-        return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr()));
+        static_assert(!std::is_const<LibObjT>::value, "Not available with `bt2::ConstBoolField`.");
+
+        bt_field_bool_set_value(this->libObjPtr(), static_cast<bt_bool>(val));
     }
 
-    operator Value() const noexcept
+    Value value() const noexcept
     {
-        return this->value();
+        return static_cast<Value>(bt_field_bool_get_value(this->libObjPtr()));
     }
 };
 
@@ -323,8 +331,7 @@ private:
     using typename CommonField<LibObjT>::_ThisCommonField;
 
 public:
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstBitArrayFieldClass,
-                                            BitArrayFieldClass>::type;
+    using Class = internal::DepType<LibObjT, BitArrayFieldClass, ConstBitArrayFieldClass>;
 
     explicit CommonBitArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
     {
@@ -338,12 +345,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayField<LibObjT>& operator=(const CommonBitArrayField<OtherLibObjT> val) noexcept
+    CommonBitArrayField<LibObjT> operator=(const CommonBitArrayField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonBitArrayField<const bt_field> asConst() const noexcept
+    {
+        return CommonBitArrayField<const bt_field> {*this};
+    }
+
     ConstBitArrayFieldClass cls() const noexcept
     {
         return ConstBitArrayFieldClass {
@@ -355,12 +367,12 @@ public:
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
-    CommonBitArrayField<LibObjT> operator=(const std::uint64_t bits) const noexcept
+    void valueAsInteger(const std::uint64_t bits) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstBitArrayField`.");
 
         bt_field_bit_array_set_value_as_integer(this->libObjPtr(), bits);
-        return *this;
     }
 
     std::uint64_t valueAsInteger() const noexcept
@@ -410,9 +422,7 @@ protected:
 
 public:
     using Value = std::uint64_t;
-
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstIntegerFieldClass,
-                                            IntegerFieldClass>::type;
+    using Class = internal::DepType<LibObjT, IntegerFieldClass, ConstIntegerFieldClass>;
 
     explicit CommonUnsignedIntegerField(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonField {libObjPtr}
@@ -427,35 +437,40 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonUnsignedIntegerField&
+    _ThisCommonUnsignedIntegerField
     operator=(const CommonUnsignedIntegerField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonUnsignedIntegerField<const bt_field> asConst() const noexcept
+    {
+        return CommonUnsignedIntegerField<const bt_field> {*this};
+    }
+
     Class cls() const noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
-    CommonUnsignedIntegerField<LibObjT> operator=(const Value val) const noexcept
+    RawValueProxy<CommonUnsignedIntegerField> operator*() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return RawValueProxy<CommonUnsignedIntegerField> {*this};
+    }
+
+    void value(const Value val) const noexcept
+    {
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstUnsignedIntegerField`.");
 
         bt_field_integer_unsigned_set_value(this->libObjPtr(), val);
-        return *this;
     }
 
     Value value() const noexcept
     {
         return bt_field_integer_unsigned_get_value(this->libObjPtr());
     }
-
-    operator Value() const noexcept
-    {
-        return this->value();
-    }
 };
 
 using UnsignedIntegerField = CommonUnsignedIntegerField<bt_field>;
@@ -493,9 +508,7 @@ protected:
 
 public:
     using Value = std::int64_t;
-
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstIntegerFieldClass,
-                                            IntegerFieldClass>::type;
+    using Class = internal::DepType<LibObjT, IntegerFieldClass, ConstIntegerFieldClass>;
 
     explicit CommonSignedIntegerField(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonField {libObjPtr}
@@ -510,35 +523,40 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonSignedIntegerField&
+    _ThisCommonSignedIntegerField
     operator=(const CommonSignedIntegerField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonSignedIntegerField<const bt_field> asConst() const noexcept
+    {
+        return CommonSignedIntegerField<const bt_field> {*this};
+    }
+
     Class cls() const noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
-    CommonSignedIntegerField<LibObjT> operator=(const Value val) const noexcept
+    RawValueProxy<CommonSignedIntegerField> operator*() const noexcept
+    {
+        return RawValueProxy<CommonSignedIntegerField> {*this};
+    }
+
+    void value(const Value val) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstSignedIntegerField`.");
 
         bt_field_integer_signed_set_value(this->libObjPtr(), val);
-        return *this;
     }
 
     Value value() const noexcept
     {
         return bt_field_integer_signed_get_value(this->libObjPtr());
     }
-
-    operator Value() const noexcept
-    {
-        return this->value();
-    }
 };
 
 using SignedIntegerField = CommonSignedIntegerField<bt_field>;
@@ -570,29 +588,23 @@ public:
     explicit EnumerationFieldClassMappingLabels(
         const bt_field_class_enumeration_mapping_label_array labels, const std::uint64_t size) :
         _mLabels {labels},
-        _mSize {size}
+        _mLen {size}
     {
     }
 
-    EnumerationFieldClassMappingLabels(const EnumerationFieldClassMappingLabels&) noexcept =
-        default;
-
-    EnumerationFieldClassMappingLabels&
-    operator=(const EnumerationFieldClassMappingLabels&) noexcept = default;
-
-    std::uint64_t size() const noexcept
+    std::uint64_t length() const noexcept
     {
-        return _mSize;
+        return _mLen;
     }
 
-    bpstd::string_view operator[](const std::uint64_t index) const noexcept
+    const char *operator[](const std::uint64_t index) const noexcept
     {
         return _mLabels[index];
     }
 
 private:
     bt_field_class_enumeration_mapping_label_array _mLabels;
-    std::uint64_t _mSize;
+    std::uint64_t _mLen;
 };
 
 template <typename LibObjT>
@@ -603,9 +615,8 @@ private:
     using typename CommonField<LibObjT>::_LibObjPtr;
 
 public:
-    using Class =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstUnsignedEnumerationFieldClass,
-                                  UnsignedEnumerationFieldClass>::type;
+    using Class = internal::DepType<LibObjT, UnsignedEnumerationFieldClass,
+                                    ConstUnsignedEnumerationFieldClass>;
 
     explicit CommonUnsignedEnumerationField(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonUnsignedIntegerField {libObjPtr}
@@ -621,14 +632,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonUnsignedEnumerationField<LibObjT>&
+    CommonUnsignedEnumerationField<LibObjT>
     operator=(const CommonUnsignedEnumerationField<OtherLibObjT> val) noexcept
     {
         _ThisCommonUnsignedIntegerField::operator=(val);
         return *this;
     }
 
-    using CommonUnsignedIntegerField<LibObjT>::operator=;
+    CommonUnsignedEnumerationField<const bt_field> asConst() const noexcept
+    {
+        return CommonUnsignedEnumerationField<const bt_field> {*this};
+    }
 
     Class cls() const noexcept
     {
@@ -682,8 +696,7 @@ private:
 
 public:
     using Class =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstSignedEnumerationFieldClass,
-                                  SignedEnumerationFieldClass>::type;
+        internal::DepType<LibObjT, SignedEnumerationFieldClass, ConstSignedEnumerationFieldClass>;
 
     explicit CommonSignedEnumerationField(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonSignedIntegerField {libObjPtr}
@@ -698,14 +711,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonSignedEnumerationField<LibObjT>&
+    CommonSignedEnumerationField<LibObjT>
     operator=(const CommonSignedEnumerationField<OtherLibObjT> val) noexcept
     {
         _ThisCommonSignedIntegerField::operator=(val);
         return *this;
     }
 
-    using CommonSignedIntegerField<LibObjT>::operator=;
+    CommonSignedEnumerationField<const bt_field> asConst() const noexcept
+    {
+        return CommonSignedEnumerationField<const bt_field> {*this};
+    }
 
     Class cls() const noexcept
     {
@@ -774,29 +790,34 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonSinglePrecisionRealField<LibObjT>&
+    CommonSinglePrecisionRealField<LibObjT>
     operator=(const CommonSinglePrecisionRealField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
-    CommonSinglePrecisionRealField<LibObjT> operator=(const Value val) const noexcept
+    CommonSinglePrecisionRealField<const bt_field> asConst() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return CommonSinglePrecisionRealField<const bt_field> {*this};
+    }
 
-        bt_field_real_single_precision_set_value(this->libObjPtr(), val);
-        return *this;
+    RawValueProxy<CommonSinglePrecisionRealField> operator*() const noexcept
+    {
+        return RawValueProxy<CommonSinglePrecisionRealField> {*this};
     }
 
-    Value value() const noexcept
+    void value(const Value val) const noexcept
     {
-        return bt_field_real_single_precision_get_value(this->libObjPtr());
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstSinglePrecisionRealField`.");
+
+        bt_field_real_single_precision_set_value(this->libObjPtr(), val);
     }
 
-    operator Value() const noexcept
+    Value value() const noexcept
     {
-        return this->value();
+        return bt_field_real_single_precision_get_value(this->libObjPtr());
     }
 };
 
@@ -847,29 +868,34 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDoublePrecisionRealField<LibObjT>&
+    CommonDoublePrecisionRealField<LibObjT>
     operator=(const CommonDoublePrecisionRealField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
-    CommonDoublePrecisionRealField<LibObjT> operator=(const Value val) const noexcept
+    CommonDoublePrecisionRealField<const bt_field> asConst() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return CommonDoublePrecisionRealField<const bt_field> {*this};
+    }
 
-        bt_field_real_double_precision_set_value(this->libObjPtr(), val);
-        return *this;
+    RawValueProxy<CommonDoublePrecisionRealField> operator*() const noexcept
+    {
+        return RawValueProxy<CommonDoublePrecisionRealField> {*this};
     }
 
-    Value value() const noexcept
+    void value(const Value val) const noexcept
     {
-        return bt_field_real_double_precision_get_value(this->libObjPtr());
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstDoublePrecisionRealField`.");
+
+        bt_field_real_double_precision_set_value(this->libObjPtr(), val);
     }
 
-    operator Value() const noexcept
+    Value value() const noexcept
     {
-        return this->value();
+        return bt_field_real_double_precision_get_value(this->libObjPtr());
     }
 };
 
@@ -904,6 +930,8 @@ private:
     using typename CommonField<LibObjT>::_ThisCommonField;
 
 public:
+    using Value = const char *;
+
     explicit CommonStringField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
     {
         BT_ASSERT_DBG(this->isString());
@@ -915,33 +943,43 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStringField<LibObjT>& operator=(const CommonStringField<OtherLibObjT> val) noexcept
+    CommonStringField<LibObjT> operator=(const CommonStringField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
-    CommonStringField<LibObjT> operator=(const char * const val) const
+    CommonStringField<const bt_field> asConst() const noexcept
+    {
+        return CommonStringField<const bt_field> {*this};
+    }
+
+    RawStringValueProxy<CommonStringField> operator*() const noexcept
+    {
+        return RawStringValueProxy<CommonStringField> {*this};
+    }
+
+    void value(const char * const val) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStringField`.");
 
         const auto status = bt_field_string_set_value(this->libObjPtr(), val);
 
         if (status == BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR) {
             throw MemoryError {};
         }
-
-        return *this;
     }
 
-    CommonStringField<LibObjT> operator=(const std::string& val) const
+    void value(const std::string& val) const
     {
-        return *this = val.data();
+        this->value(val.data());
     }
 
     void append(const char * const begin, const std::uint64_t len) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStringField`.");
 
         const auto status = bt_field_string_append_with_length(this->libObjPtr(), begin, len);
 
@@ -957,12 +995,13 @@ public:
 
     void clear() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStringField`.");
 
         bt_field_string_clear(this->libObjPtr());
     }
 
-    bpstd::string_view value() const noexcept
+    const char *value() const noexcept
     {
         return bt_field_string_get_value(this->libObjPtr());
     }
@@ -1036,8 +1075,7 @@ private:
     using _Spec = internal::CommonStructureFieldSpec<LibObjT>;
 
 public:
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClass,
-                                            StructureFieldClass>::type;
+    using Class = internal::DepType<LibObjT, StructureFieldClass, ConstStructureFieldClass>;
 
     explicit CommonStructureField(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonField {libObjPtr}
@@ -1052,20 +1090,25 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureField<LibObjT>& operator=(const CommonStructureField<OtherLibObjT> val) noexcept
+    CommonStructureField<LibObjT> operator=(const CommonStructureField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonStructureField<const bt_field> asConst() const noexcept
+    {
+        return CommonStructureField<const bt_field> {*this};
+    }
+
     Class cls() const noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
     }
 
-    std::uint64_t size() const noexcept
+    std::uint64_t length() const noexcept
     {
-        return this->cls().size();
+        return this->cls().length();
     }
 
     CommonField<LibObjT> operator[](const std::uint64_t index) const noexcept
@@ -1073,7 +1116,7 @@ public:
         return CommonField<LibObjT> {_Spec::memberFieldByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<CommonField<LibObjT>> operator[](const char * const name) const noexcept
+    bt2s::optional<CommonField<LibObjT>> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr = _Spec::memberFieldByName(this->libObjPtr(), name);
 
@@ -1081,10 +1124,10 @@ public:
             return CommonField<LibObjT> {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<CommonField<LibObjT>> operator[](const std::string& name) const noexcept
+    bt2s::optional<CommonField<LibObjT>> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
@@ -1150,8 +1193,7 @@ protected:
     using _ThisCommonArrayField = CommonArrayField<LibObjT>;
 
 public:
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstArrayFieldClass,
-                                            ArrayFieldClass>::type;
+    using Class = internal::DepType<LibObjT, ArrayFieldClass, ConstArrayFieldClass>;
 
     explicit CommonArrayField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
     {
@@ -1164,12 +1206,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    _ThisCommonArrayField& operator=(const CommonArrayField<OtherLibObjT> val) noexcept
+    _ThisCommonArrayField operator=(const CommonArrayField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonArrayField<const bt_field> asConst() const noexcept
+    {
+        return CommonArrayField<const bt_field> {*this};
+    }
+
     Class cls() const noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
@@ -1230,13 +1277,18 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonDynamicArrayField<LibObjT>&
+    CommonDynamicArrayField<LibObjT>
     operator=(const CommonDynamicArrayField<OtherLibObjT> val) noexcept
     {
         _ThisCommonArrayField::operator=(val);
         return *this;
     }
 
+    CommonDynamicArrayField<const bt_field> asConst() const noexcept
+    {
+        return CommonDynamicArrayField<const bt_field> {*this};
+    }
+
     std::uint64_t length() const noexcept
     {
         return _ThisCommonArrayField::length();
@@ -1244,7 +1296,8 @@ public:
 
     void length(const std::uint64_t length) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstDynamicArrayField`.");
 
         const auto status = bt_field_array_dynamic_set_length(this->libObjPtr(), length);
 
@@ -1309,8 +1362,7 @@ private:
     using _Spec = internal::CommonOptionFieldSpec<LibObjT>;
 
 public:
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstOptionFieldClass,
-                                            OptionFieldClass>::type;
+    using Class = internal::DepType<LibObjT, OptionFieldClass, ConstOptionFieldClass>;
 
     explicit CommonOptionField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
     {
@@ -1323,12 +1375,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionField<LibObjT>& operator=(const CommonOptionField<OtherLibObjT> val) noexcept
+    CommonOptionField<LibObjT> operator=(const CommonOptionField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonOptionField<const bt_field> asConst() const noexcept
+    {
+        return CommonOptionField<const bt_field> {*this};
+    }
+
     Class cls() const noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
@@ -1336,7 +1393,8 @@ public:
 
     void hasField(const bool hasField) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstOptionField`.");
 
         bt_field_option_set_has_field(this->libObjPtr(), static_cast<bt_bool>(hasField));
     }
@@ -1346,7 +1404,7 @@ public:
         return this->field().has_value();
     }
 
-    nonstd::optional<CommonField<LibObjT>> field() const noexcept
+    bt2s::optional<CommonField<LibObjT>> field() const noexcept
     {
         const auto libObjPtr = _Spec::field(this->libObjPtr());
 
@@ -1354,7 +1412,7 @@ public:
             return CommonField<LibObjT> {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 };
 
@@ -1413,8 +1471,7 @@ private:
     using _Spec = internal::CommonVariantFieldSpec<LibObjT>;
 
 public:
-    using Class = typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClass,
-                                            VariantFieldClass>::type;
+    using Class = internal::DepType<LibObjT, VariantFieldClass, ConstVariantFieldClass>;
 
     explicit CommonVariantField(const _LibObjPtr libObjPtr) noexcept : _ThisCommonField {libObjPtr}
     {
@@ -1427,12 +1484,17 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantField<LibObjT>& operator=(const CommonVariantField<OtherLibObjT> val) noexcept
+    CommonVariantField<LibObjT> operator=(const CommonVariantField<OtherLibObjT> val) noexcept
     {
         _ThisCommonField::operator=(val);
         return *this;
     }
 
+    CommonVariantField<const bt_field> asConst() const noexcept
+    {
+        return CommonVariantField<const bt_field> {*this};
+    }
+
     Class cls() const noexcept
     {
         return Class {internal::CommonFieldSpec<LibObjT>::cls(this->libObjPtr())};
@@ -1440,7 +1502,8 @@ public:
 
     void selectOption(const std::uint64_t index) const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstVariantField`.");
 
         static_cast<void>(bt_field_variant_select_option_by_index(this->libObjPtr(), index));
     }
This page took 0.032261 seconds and 4 git commands to generate.