cpp-common: add `bt2s::optional`, alias of `nonstd::optional`
[babeltrace.git] / src / cpp-common / bt2 / field-class.hpp
index a7c4ba4bc274e677f3219068437437c55e20500a..94cdb8e6de036f2cd94ece042011537d39ede863 100644 (file)
@@ -7,20 +7,21 @@
 #ifndef BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
 #define BABELTRACE_CPP_COMMON_BT2_FIELD_CLASS_HPP
 
-#include <type_traits>
 #include <cstdint>
+#include <type_traits>
+
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
-#include "internal/borrowed-obj.hpp"
-#include "internal/shared-obj.hpp"
-#include "internal/utils.hpp"
-#include "cpp-common/optional.hpp"
-#include "cpp-common/string_view.hpp"
-#include "common-iter.hpp"
-#include "lib-error.hpp"
-#include "integer-range-set.hpp"
+#include "cpp-common/bt2s/optional.hpp"
+
+#include "borrowed-object-iterator.hpp"
+#include "borrowed-object.hpp"
+#include "exc.hpp"
 #include "field-path.hpp"
+#include "integer-range-set.hpp"
+#include "internal/utils.hpp"
+#include "shared-object.hpp"
 #include "value.hpp"
 
 namespace bt2 {
@@ -28,20 +29,17 @@ namespace internal {
 
 struct FieldClassRefFuncs final
 {
-    static void get(const bt_field_class * const libObjPtr)
+    static void get(const bt_field_class * const libObjPtr) noexcept
     {
         bt_field_class_get_ref(libObjPtr);
     }
 
-    static void put(const bt_field_class * const libObjPtr)
+    static void put(const bt_field_class * const libObjPtr) noexcept
     {
         bt_field_class_put_ref(libObjPtr);
     }
 };
 
-template <typename ObjT, typename LibObjT>
-using SharedFieldClass = internal::SharedObj<ObjT, LibObjT, internal::FieldClassRefFuncs>;
-
 template <typename LibObjT>
 struct CommonFieldClassSpec;
 
@@ -67,6 +65,9 @@ struct CommonFieldClassSpec<const bt_field_class> final
 
 } /* namespace internal */
 
+template <typename ObjT, typename LibObjT>
+using SharedFieldClass = SharedObject<ObjT, LibObjT, internal::FieldClassRefFuncs>;
+
 template <typename LibObjT>
 class CommonBitArrayFieldClass;
 
@@ -159,60 +160,40 @@ enum class FieldClassType
 };
 
 template <typename LibObjT>
-class CommonFieldClass : public internal::BorrowedObj<LibObjT>
+class CommonFieldClass : public BorrowedObject<LibObjT>
 {
-    /* Allow appendMember() to call `fc.libObjPtr()` */
-    friend class CommonStructureFieldClass<bt_field_class>;
-
-    /* Allow appendOption() to call `fc.libObjPtr()` */
-    friend class CommonVariantWithoutSelectorFieldClass<bt_field_class>;
-
-    friend class CommonVariantWithIntegerSelectorFieldClass<
-        bt_field_class,
-        ConstVariantWithIntegerSelectorFieldClassOption<
-            const bt_field_class_variant_with_selector_field_integer_unsigned_option>>;
-
-    friend class CommonVariantWithIntegerSelectorFieldClass<
-        bt_field_class,
-        ConstVariantWithIntegerSelectorFieldClassOption<
-            const bt_field_class_variant_with_selector_field_integer_signed_option>>;
-
-    /* Allow *FieldClass() to call `fc.libObjPtr()` */
-    friend class CommonEventClass<bt_event_class>;
-    friend class CommonStreamClass<bt_stream_class>;
-
-    /* Allow create*FieldClass() to call `fc.libObjPtr()` */
-    friend class CommonTraceClass<bt_trace_class>;
-
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
 
 protected:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _ThisCommonFieldClass = CommonFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonFieldClass<LibObjT>, LibObjT>;
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
 
-    using UserAttributes =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstMapValue, MapValue>::type;
-
-    explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObj {libObjPtr}
+    explicit CommonFieldClass(const _LibObjPtr libObjPtr) noexcept : _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonFieldClass(const CommonFieldClass<OtherLibObjT>& fc) noexcept : _ThisBorrowedObj {fc}
+    CommonFieldClass(const CommonFieldClass<OtherLibObjT> fc) noexcept : _ThisBorrowedObject {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonFieldClass& operator=(const CommonFieldClass<OtherLibObjT>& fc) noexcept
+    CommonFieldClass operator=(const CommonFieldClass<OtherLibObjT> fc) noexcept
     {
-        _ThisBorrowedObj::operator=(fc);
+        _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
+    CommonFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonFieldClass<const bt_field_class> {*this};
+    }
+
     FieldClassType type() const noexcept
     {
         return static_cast<FieldClassType>(bt_field_class_get_type(this->libObjPtr()));
@@ -373,6 +354,12 @@ public:
         return this->_libTypeIs(BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD);
     }
 
+    template <typename FieldClassT>
+    FieldClassT as() const noexcept
+    {
+        return FieldClassT {this->libObjPtr()};
+    }
+
     CommonBitArrayFieldClass<LibObjT> asBitArray() const noexcept;
     CommonIntegerFieldClass<LibObjT> asInteger() const noexcept;
     CommonBaseEnumerationFieldClass<LibObjT> asEnumeration() const noexcept;
@@ -413,20 +400,14 @@ public:
     asVariantWithSignedIntegerSelector() const noexcept;
 
     template <typename LibValT>
-    void userAttributes(const CommonMapValue<LibValT>& userAttrs)
+    void userAttributes(const CommonMapValue<LibValT> userAttrs) 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::ConstFieldClass`.");
 
         bt_field_class_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
     }
 
-    ConstMapValue userAttributes() const noexcept
-    {
-        return ConstMapValue {internal::CommonFieldClassSpec<const bt_field_class>::userAttributes(
-            this->libObjPtr())};
-    }
-
-    UserAttributes userAttributes() noexcept
+    UserAttributes userAttributes() const noexcept
     {
         return UserAttributes {
             internal::CommonFieldClassSpec<LibObjT>::userAttributes(this->libObjPtr())};
@@ -475,7 +456,7 @@ private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonBitArrayFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonBitArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
@@ -484,19 +465,24 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonBitArrayFieldClass(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonBitArrayFieldClass<LibObjT>&
-    operator=(const CommonBitArrayFieldClass<OtherLibObjT>& fc) noexcept
+    CommonBitArrayFieldClass<LibObjT>
+    operator=(const CommonBitArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonBitArrayFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonBitArrayFieldClass<const bt_field_class> {*this};
+    }
+
     std::uint64_t length() const noexcept
     {
         return bt_field_class_bit_array_get_length(this->libObjPtr());
@@ -550,7 +536,7 @@ protected:
     using _ThisCommonIntegerFieldClass = CommonIntegerFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonIntegerFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonIntegerFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
@@ -559,21 +545,27 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonIntegerFieldClass(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonIntegerFieldClass& operator=(const CommonIntegerFieldClass<OtherLibObjT>& fc) noexcept
+    CommonIntegerFieldClass operator=(const CommonIntegerFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    void fieldValueRange(const std::uint64_t n) noexcept
+    CommonIntegerFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonIntegerFieldClass<const bt_field_class> {*this};
+    }
+
+    void fieldValueRange(const std::uint64_t n) 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::ConstIntegerFieldClass`.");
 
         bt_field_class_integer_set_field_value_range(this->libObjPtr(), n);
     }
@@ -583,9 +575,10 @@ public:
         return bt_field_class_integer_get_field_value_range(this->libObjPtr());
     }
 
-    void preferredDisplayBase(const DisplayBase base) noexcept
+    void preferredDisplayBase(const DisplayBase base) 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::ConstIntegerFieldClass`.");
 
         bt_field_class_integer_set_preferred_display_base(
             this->libObjPtr(), static_cast<bt_field_class_integer_preferred_display_base>(base));
@@ -624,10 +617,6 @@ struct TypeDescr<ConstIntegerFieldClass> : public IntegerFieldClassTypeDescr
 {
 };
 
-} /* namespace internal */
-
-namespace internal {
-
 template <typename LibObjT>
 struct ConstEnumerationFieldClassMappingSpec;
 
@@ -671,11 +660,11 @@ struct ConstEnumerationFieldClassMappingSpec<const bt_field_class_enumeration_si
 } /* namespace internal */
 
 template <typename LibObjT>
-class ConstEnumerationFieldClassMapping final : public internal::BorrowedObj<LibObjT>
+class ConstEnumerationFieldClassMapping final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
 
 public:
     using RangeSet = typename std::conditional<
@@ -683,19 +672,19 @@ public:
         ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
 
     explicit ConstEnumerationFieldClassMapping(const _LibObjPtr libObjPtr) noexcept :
-        _ThisBorrowedObj {libObjPtr}
+        _ThisBorrowedObject {libObjPtr}
     {
     }
 
     ConstEnumerationFieldClassMapping(const ConstEnumerationFieldClassMapping& mapping) noexcept :
-        _ThisBorrowedObj {mapping}
+        _ThisBorrowedObject {mapping}
     {
     }
 
-    ConstEnumerationFieldClassMapping&
+    ConstEnumerationFieldClassMapping
     operator=(const ConstEnumerationFieldClassMapping& mapping) noexcept
     {
-        _ThisBorrowedObj::operator=(mapping);
+        _ThisBorrowedObject::operator=(mapping);
         return *this;
     }
 
@@ -705,7 +694,7 @@ public:
             internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::ranges(this->libObjPtr())};
     }
 
-    bpstd::string_view label() const noexcept
+    const char *label() const noexcept
     {
         return internal::ConstEnumerationFieldClassMappingSpec<LibObjT>::label(this->libObjPtr());
     }
@@ -783,7 +772,7 @@ protected:
     using _ThisCommonBaseEnumerationFieldClass = CommonBaseEnumerationFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
+    using Shared = SharedFieldClass<_ThisCommonBaseEnumerationFieldClass, LibObjT>;
 
     explicit CommonBaseEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonIntegerFieldClass {libObjPtr}
@@ -792,21 +781,26 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonBaseEnumerationFieldClass(
-        const CommonBaseEnumerationFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonBaseEnumerationFieldClass(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
+        :
         _ThisCommonIntegerFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonBaseEnumerationFieldClass&
-    operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT>& fc) noexcept
+    CommonBaseEnumerationFieldClass
+    operator=(const CommonBaseEnumerationFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonIntegerFieldClass::operator=(fc);
         return *this;
     }
 
-    std::uint64_t size() const noexcept
+    CommonBaseEnumerationFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonBaseEnumerationFieldClass<const bt_field_class> {*this};
+    }
+
+    std::uint64_t length() const noexcept
     {
         return bt_field_class_enumeration_get_mapping_count(this->libObjPtr());
     }
@@ -823,11 +817,10 @@ class CommonEnumerationFieldClass final : public CommonBaseEnumerationFieldClass
 private:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using typename CommonBaseEnumerationFieldClass<LibObjT>::_ThisCommonBaseEnumerationFieldClass;
-    using _ThisCommonEnumerationFieldClass = CommonEnumerationFieldClass<LibObjT, MappingT>;
 
 public:
-    using Shared = internal::SharedFieldClass<_ThisCommonEnumerationFieldClass, LibObjT>;
-    using Iterator = CommonIterator<CommonEnumerationFieldClass, MappingT>;
+    using Shared = SharedFieldClass<CommonEnumerationFieldClass, LibObjT>;
+    using Iterator = BorrowedObjectIterator<CommonEnumerationFieldClass>;
     using Mapping = MappingT;
 
     explicit CommonEnumerationFieldClass(const _LibObjPtr libObjPtr) noexcept :
@@ -838,16 +831,16 @@ public:
 
     template <typename OtherLibObjT>
     CommonEnumerationFieldClass(
-        const CommonEnumerationFieldClass<OtherLibObjT, MappingT>& fc) noexcept :
-        _ThisCommonEnumerationFieldClass {fc}
+        const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept :
+        CommonEnumerationFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonEnumerationFieldClass&
-    operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT>& fc) noexcept
+    CommonEnumerationFieldClass
+    operator=(const CommonEnumerationFieldClass<OtherLibObjT, MappingT> fc) noexcept
     {
-        _ThisCommonEnumerationFieldClass::operator=(fc);
+        CommonEnumerationFieldClass::operator=(fc);
         return *this;
     }
 
@@ -857,7 +850,7 @@ public:
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Mapping> operator[](const char * const label) const noexcept
+    bt2s::optional<Mapping> operator[](const char * const label) const noexcept
     {
         const auto libObjPtr = internal::CommonEnumerationFieldClassSpec<MappingT>::mappingByLabel(
             this->libObjPtr(), label);
@@ -866,25 +859,25 @@ public:
             return Mapping {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Mapping> operator[](const std::string& label) const noexcept
+    bt2s::optional<Mapping> operator[](const std::string& label) const noexcept
     {
         return (*this)[label.data()];
     }
 
-    void addMapping(const char * const label, const typename Mapping::RangeSet ranges)
+    void addMapping(const char * const label, const typename Mapping::RangeSet ranges) const
     {
         const auto status = internal::CommonEnumerationFieldClassSpec<MappingT>::addMapping(
             this->libObjPtr(), label, ranges.libObjPtr());
 
         if (status == BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
-    void addMapping(const std::string& label, const typename Mapping::RangeSet ranges)
+    void addMapping(const std::string& label, const typename Mapping::RangeSet ranges) const
     {
         this->addMapping(label.data(), ranges);
     }
@@ -896,7 +889,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Shared shared() const noexcept
@@ -965,6 +958,11 @@ struct CommonStructureFieldClassMemberSpec<bt_field_class_structure_member> fina
     {
         return bt_field_class_structure_member_borrow_field_class(libObjPtr);
     }
+
+    static bt_value *userAttributes(bt_field_class_structure_member * const libObjPtr) noexcept
+    {
+        return bt_field_class_structure_member_borrow_user_attributes(libObjPtr);
+    }
 };
 
 /* Functions specific to constant structure field class members */
@@ -976,57 +974,79 @@ struct CommonStructureFieldClassMemberSpec<const bt_field_class_structure_member
     {
         return bt_field_class_structure_member_borrow_field_class_const(libObjPtr);
     }
+
+    static const bt_value *
+    userAttributes(const bt_field_class_structure_member * const libObjPtr) noexcept
+    {
+        return bt_field_class_structure_member_borrow_user_attributes_const(libObjPtr);
+    }
 };
 
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonStructureFieldClassMember final : public internal::BorrowedObj<LibObjT>
+class CommonStructureFieldClassMember final : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using _FieldClass = internal::DepFc<LibObjT>;
 
 public:
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
+
     explicit CommonStructureFieldClassMember(const _LibObjPtr libObjPtr) noexcept :
-        _ThisBorrowedObj {libObjPtr}
+        _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClassMember(
-        const CommonStructureFieldClassMember<OtherLibObjT>& fc) noexcept :
-        _ThisBorrowedObj {fc}
+    CommonStructureFieldClassMember(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
+        :
+        _ThisBorrowedObject {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClassMember<LibObjT>&
-    operator=(const CommonStructureFieldClassMember<OtherLibObjT>& fc) noexcept
+    CommonStructureFieldClassMember<LibObjT>
+    operator=(const CommonStructureFieldClassMember<OtherLibObjT> fc) noexcept
     {
-        _ThisBorrowedObj::operator=(fc);
+        _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
-    bpstd::string_view name() const noexcept
+    CommonStructureFieldClassMember<const bt_field_class_structure_member> asConst() const noexcept
     {
-        return bt_field_class_structure_member_get_name(this->libObjPtr());
+        return CommonStructureFieldClassMember<const bt_field_class_structure_member> {*this};
     }
 
-    ConstFieldClass fieldClass() const noexcept
+    const char *name() const noexcept
     {
-        return ConstFieldClass {internal::CommonStructureFieldClassMemberSpec<
-            const bt_field_class_structure_member>::fieldClass(this->libObjPtr())};
+        return bt_field_class_structure_member_get_name(this->libObjPtr());
     }
 
-    _FieldClass fieldClass() noexcept
+    _FieldClass fieldClass() const noexcept
     {
         return _FieldClass {
             internal::CommonStructureFieldClassMemberSpec<LibObjT>::fieldClass(this->libObjPtr())};
     }
+
+    template <typename LibValT>
+    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    {
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStructureFieldClassMember`.");
+
+        bt_field_class_structure_member_set_user_attributes(this->libObjPtr(),
+                                                            userAttrs.libObjPtr());
+    }
+
+    UserAttributes userAttributes() const noexcept
+    {
+        return UserAttributes {
+            internal::CommonStructureFieldClassMemberSpec<LibObjT>::userAttributes(
+                this->libObjPtr())};
+    }
 };
 
 using StructureFieldClassMember = CommonStructureFieldClassMember<bt_field_class_structure_member>;
@@ -1099,12 +1119,11 @@ private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
-    using Member =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstStructureFieldClassMember,
-                                  StructureFieldClassMember>::type;
+    using Shared = SharedFieldClass<CommonStructureFieldClass<LibObjT>, LibObjT>;
+    using Iterator = BorrowedObjectIterator<CommonStructureFieldClass<LibObjT>>;
 
-    using Iterator = CommonIterator<CommonStructureFieldClass<LibObjT>, Member>;
+    using Member =
+        internal::DepType<LibObjT, StructureFieldClassMember, ConstStructureFieldClassMember>;
 
     explicit CommonStructureFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
@@ -1113,36 +1132,42 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonStructureFieldClass(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStructureFieldClass& operator=(const CommonStructureFieldClass<OtherLibObjT>& fc) noexcept
+    CommonStructureFieldClass operator=(const CommonStructureFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    void appendMember(const char * const name, const FieldClass& fc)
+    CommonStructureFieldClass<const bt_field_class> asConst() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return CommonStructureFieldClass<const bt_field_class> {*this};
+    }
+
+    void appendMember(const char * const name, const FieldClass fc) const
+    {
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstStructureFieldClass`.");
 
         const auto status =
             bt_field_class_structure_append_member(this->libObjPtr(), name, fc.libObjPtr());
 
         if (status == BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
-    void appendMember(const std::string& name, const FieldClass& fc)
+    void appendMember(const std::string& name, const FieldClass fc) const
     {
         this->appendMember(name.data(), fc);
     }
 
-    std::uint64_t size() const noexcept
+    std::uint64_t length() const noexcept
     {
         return bt_field_class_structure_get_member_count(this->libObjPtr());
     }
@@ -1154,43 +1179,16 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
-    }
-
-    ConstStructureFieldClassMember operator[](const std::uint64_t index) const noexcept
-    {
-        return ConstStructureFieldClassMember {
-            internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByIndex(
-                this->libObjPtr(), index)};
+        return Iterator {*this, this->length()};
     }
 
-    Member operator[](const std::uint64_t index) noexcept
+    Member operator[](const std::uint64_t index) const noexcept
     {
         return Member {internal::CommonStructureFieldClassSpec<LibObjT>::memberByIndex(
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<ConstStructureFieldClassMember>
-    operator[](const char * const name) const noexcept
-    {
-        const auto libObjPtr =
-            internal::CommonStructureFieldClassSpec<const bt_field_class>::memberByName(
-                this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return ConstStructureFieldClassMember {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<ConstStructureFieldClassMember>
-    operator[](const std::string& name) const noexcept
-    {
-        return (*this)[name.data()];
-    }
-
-    nonstd::optional<Member> operator[](const char * const name) noexcept
+    bt2s::optional<Member> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr =
             internal::CommonStructureFieldClassSpec<LibObjT>::memberByName(this->libObjPtr(), name);
@@ -1199,10 +1197,10 @@ public:
             return Member {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Member> operator[](const std::string& name) noexcept
+    bt2s::optional<Member> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
@@ -1264,16 +1262,14 @@ class CommonArrayFieldClass : public CommonFieldClass<LibObjT>
 {
 private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using _FieldClass = internal::DepFc<LibObjT>;
 
 protected:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonArrayFieldClass = CommonArrayFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonArrayFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
@@ -1282,26 +1278,24 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonArrayFieldClass(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonArrayFieldClass& operator=(const CommonArrayFieldClass<OtherLibObjT>& fc) noexcept
+    CommonArrayFieldClass operator=(const CommonArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    ConstFieldClass elementFieldClass() const noexcept
+    CommonArrayFieldClass<const bt_field_class> asConst() const noexcept
     {
-        return ConstFieldClass {
-            internal::CommonArrayFieldClassSpec<const bt_field_class>::elementFieldClass(
-                this->libObjPtr())};
+        return CommonArrayFieldClass<const bt_field_class> {*this};
     }
 
-    _FieldClass elementFieldClass() noexcept
+    _FieldClass elementFieldClass() const noexcept
     {
         return _FieldClass {
             internal::CommonArrayFieldClassSpec<LibObjT>::elementFieldClass(this->libObjPtr())};
@@ -1344,7 +1338,7 @@ private:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonStaticArrayFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonStaticArrayFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonArrayFieldClass {libObjPtr}
@@ -1353,19 +1347,24 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonStaticArrayFieldClass(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonArrayFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonStaticArrayFieldClass&
-    operator=(const CommonStaticArrayFieldClass<OtherLibObjT>& fc) noexcept
+    CommonStaticArrayFieldClass
+    operator=(const CommonStaticArrayFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonArrayFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonStaticArrayFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonStaticArrayFieldClass<const bt_field_class> {*this};
+    }
+
     std::uint64_t length() const noexcept
     {
         return bt_field_class_array_static_get_length(this->libObjPtr());
@@ -1408,8 +1407,7 @@ private:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
 public:
-    using Shared =
-        internal::SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonDynamicArrayWithLengthFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonDynamicArrayWithLengthFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonArrayFieldClass {libObjPtr}
@@ -1419,19 +1417,24 @@ public:
 
     template <typename OtherLibObjT>
     CommonDynamicArrayWithLengthFieldClass(
-        const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT>& fc) noexcept :
+        const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonArrayFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonDynamicArrayWithLengthFieldClass&
-    operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT>& fc) noexcept
+    CommonDynamicArrayWithLengthFieldClass
+    operator=(const CommonDynamicArrayWithLengthFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonArrayFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonDynamicArrayWithLengthFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonDynamicArrayWithLengthFieldClass<const bt_field_class> {*this};
+    }
+
     ConstFieldPath lengthFieldPath() const noexcept
     {
         return ConstFieldPath {
@@ -1500,16 +1503,14 @@ class CommonOptionFieldClass : public CommonFieldClass<LibObjT>
 {
 private:
     using typename CommonFieldClass<LibObjT>::_ThisCommonFieldClass;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using _FieldClass = internal::DepFc<LibObjT>;
 
 protected:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
     using _ThisCommonOptionFieldClass = CommonOptionFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonOptionFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonOptionFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
@@ -1518,26 +1519,24 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonOptionFieldClass(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonOptionFieldClass& operator=(const CommonOptionFieldClass<OtherLibObjT>& fc) noexcept
+    CommonOptionFieldClass operator=(const CommonOptionFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    ConstFieldClass fieldClass() const noexcept
+    CommonOptionFieldClass<const bt_field_class> asConst() const noexcept
     {
-        return ConstFieldClass {
-            internal::CommonOptionFieldClassSpec<const bt_field_class>::fieldClass(
-                this->libObjPtr())};
+        return CommonOptionFieldClass<const bt_field_class> {*this};
     }
 
-    _FieldClass fieldClass() noexcept
+    _FieldClass fieldClass() const noexcept
     {
         return _FieldClass {
             internal::CommonOptionFieldClassSpec<LibObjT>::fieldClass(this->libObjPtr())};
@@ -1583,7 +1582,7 @@ protected:
     using _ThisCommonOptionWithSelectorFieldClass = CommonOptionWithSelectorFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonOptionWithSelectorFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonOptionWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonOptionFieldClass {libObjPtr}
@@ -1593,19 +1592,24 @@ public:
 
     template <typename OtherLibObjT>
     CommonOptionWithSelectorFieldClass(
-        const CommonOptionWithSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+        const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonOptionFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithSelectorFieldClass&
-    operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT>& fc) noexcept
+    CommonOptionWithSelectorFieldClass
+    operator=(const CommonOptionWithSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonOptionFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonOptionWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonOptionWithSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     ConstFieldPath selectorFieldPath() const noexcept
     {
         return ConstFieldPath {
@@ -1652,8 +1656,7 @@ private:
         LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
 
 public:
-    using Shared =
-        internal::SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonOptionWithBoolSelectorFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonOptionWithBoolSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonOptionWithSelectorFieldClass {libObjPtr}
@@ -1663,19 +1666,24 @@ public:
 
     template <typename OtherLibObjT>
     CommonOptionWithBoolSelectorFieldClass(
-        const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+        const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonOptionWithSelectorFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithBoolSelectorFieldClass&
-    operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT>& fc) noexcept
+    CommonOptionWithBoolSelectorFieldClass
+    operator=(const CommonOptionWithBoolSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonOptionWithBoolSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonOptionWithBoolSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     bool selectorIsReversed() const noexcept
     {
         return bt_field_class_option_with_selector_field_bool_selector_is_reversed(
@@ -1751,13 +1759,8 @@ private:
     using typename CommonOptionWithSelectorFieldClass<
         LibObjT>::_ThisCommonOptionWithSelectorFieldClass;
 
-    using _ThisCommonOptionWithIntegerSelectorFieldClass =
-        CommonOptionWithIntegerSelectorFieldClass<LibObjT, RangeSetT>;
-
 public:
-    using Shared =
-        internal::SharedFieldClass<_ThisCommonOptionWithIntegerSelectorFieldClass, LibObjT>;
-
+    using Shared = SharedFieldClass<CommonOptionWithIntegerSelectorFieldClass, LibObjT>;
     using RangeSet = RangeSetT;
 
     explicit CommonOptionWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
@@ -1768,14 +1771,14 @@ public:
 
     template <typename OtherLibObjT>
     CommonOptionWithIntegerSelectorFieldClass(
-        const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT>& fc) noexcept :
+        const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept :
         _ThisCommonOptionWithSelectorFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonOptionWithIntegerSelectorFieldClass&
-    operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT>& fc) noexcept
+    CommonOptionWithIntegerSelectorFieldClass
+    operator=(const CommonOptionWithIntegerSelectorFieldClass<OtherLibObjT, RangeSetT> fc) noexcept
     {
         _ThisCommonOptionWithSelectorFieldClass::operator=(fc);
         return *this;
@@ -1854,6 +1857,11 @@ struct CommonVariantFieldClassOptionSpec<bt_field_class_variant_option> final
     {
         return bt_field_class_variant_option_borrow_field_class(libObjPtr);
     }
+
+    static bt_value *userAttributes(bt_field_class_variant_option * const libObjPtr) noexcept
+    {
+        return bt_field_class_variant_option_borrow_user_attributes(libObjPtr);
+    }
 };
 
 /* Functions specific to constant variant field class options */
@@ -1865,56 +1873,76 @@ struct CommonVariantFieldClassOptionSpec<const bt_field_class_variant_option> fi
     {
         return bt_field_class_variant_option_borrow_field_class_const(libObjPtr);
     }
+
+    static const bt_value *
+    userAttributes(const bt_field_class_variant_option * const libObjPtr) noexcept
+    {
+        return bt_field_class_variant_option_borrow_user_attributes_const(libObjPtr);
+    }
 };
 
 } /* namespace internal */
 
 template <typename LibObjT>
-class CommonVariantFieldClassOption : public internal::BorrowedObj<LibObjT>
+class CommonVariantFieldClassOption : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
-
-    using _FieldClass =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstFieldClass, FieldClass>::type;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
+    using _FieldClass = internal::DepFc<LibObjT>;
 
 public:
+    using UserAttributes = internal::DepUserAttrs<LibObjT>;
+
     explicit CommonVariantFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
-        _ThisBorrowedObj {libObjPtr}
+        _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT>& fc) noexcept :
-        _ThisBorrowedObj {fc}
+    CommonVariantFieldClassOption(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept :
+        _ThisBorrowedObject {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClassOption&
-    operator=(const CommonVariantFieldClassOption<OtherLibObjT>& fc) noexcept
+    CommonVariantFieldClassOption
+    operator=(const CommonVariantFieldClassOption<OtherLibObjT> fc) noexcept
     {
-        _ThisBorrowedObj::operator=(fc);
+        _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
-    bpstd::string_view name() const noexcept
+    CommonVariantFieldClassOption<const bt_field_class_variant_option> asConst() const noexcept
     {
-        return bt_field_class_variant_option_get_name(this->libObjPtr());
+        return CommonVariantFieldClassOption<const bt_field_class_variant_option> {*this};
     }
 
-    ConstFieldClass fieldClass() const noexcept
+    const char *name() const noexcept
     {
-        return ConstFieldClass {internal::CommonVariantFieldClassOptionSpec<
-            const bt_field_class_variant_option>::fieldClass(this->libObjPtr())};
+        return bt_field_class_variant_option_get_name(this->libObjPtr());
     }
 
-    _FieldClass fieldClass() noexcept
+    _FieldClass fieldClass() const noexcept
     {
         return _FieldClass {
             internal::CommonVariantFieldClassOptionSpec<LibObjT>::fieldClass(this->libObjPtr())};
     }
+
+    template <typename LibValT>
+    void userAttributes(const CommonMapValue<LibValT> userAttrs) const noexcept
+    {
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstVariantFieldClassOption`.");
+
+        bt_field_class_variant_option_set_user_attributes(this->libObjPtr(), userAttrs.libObjPtr());
+    }
+
+    UserAttributes userAttributes() const noexcept
+    {
+        return UserAttributes {internal::CommonVariantFieldClassOptionSpec<LibObjT>::userAttributes(
+            this->libObjPtr())};
+    }
 };
 
 using VariantFieldClassOption = CommonVariantFieldClassOption<bt_field_class_variant_option>;
@@ -1992,11 +2020,11 @@ struct ConstVariantWithIntegerSelectorFieldClassOptionSpec<
 } /* namespace internal */
 
 template <typename LibObjT>
-class ConstVariantWithIntegerSelectorFieldClassOption : public internal::BorrowedObj<LibObjT>
+class ConstVariantWithIntegerSelectorFieldClassOption : public BorrowedObject<LibObjT>
 {
 private:
-    using typename internal::BorrowedObj<LibObjT>::_ThisBorrowedObj;
-    using typename internal::BorrowedObj<LibObjT>::_LibObjPtr;
+    using typename BorrowedObject<LibObjT>::_ThisBorrowedObject;
+    using typename BorrowedObject<LibObjT>::_LibObjPtr;
     using _Spec = internal::ConstVariantWithIntegerSelectorFieldClassOptionSpec<LibObjT>;
 
 public:
@@ -2007,22 +2035,22 @@ public:
         ConstUnsignedIntegerRangeSet, ConstSignedIntegerRangeSet>::type;
 
     explicit ConstVariantWithIntegerSelectorFieldClassOption(const _LibObjPtr libObjPtr) noexcept :
-        _ThisBorrowedObj {libObjPtr}
+        _ThisBorrowedObject {libObjPtr}
     {
     }
 
     template <typename OtherLibObjT>
     ConstVariantWithIntegerSelectorFieldClassOption(
-        const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT>& fc) noexcept :
-        _ThisBorrowedObj {fc}
+        const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept :
+        _ThisBorrowedObject {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    ConstVariantWithIntegerSelectorFieldClassOption&
-    operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT>& fc) noexcept
+    ConstVariantWithIntegerSelectorFieldClassOption
+    operator=(const ConstVariantWithIntegerSelectorFieldClassOption<OtherLibObjT> fc) noexcept
     {
-        _ThisBorrowedObj::operator=(fc);
+        _ThisBorrowedObject::operator=(fc);
         return *this;
     }
 
@@ -2031,7 +2059,7 @@ public:
         return ConstVariantFieldClassOption {_Spec::asBaseOption(this->libObjPtr())};
     }
 
-    bpstd::string_view name() const noexcept
+    const char *name() const noexcept
     {
         return this->asBaseOption().name();
     }
@@ -2107,13 +2135,11 @@ protected:
     using _ThisCommonVariantFieldClass = CommonVariantFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonVariantFieldClass<LibObjT>, LibObjT>;
+    using Iterator = BorrowedObjectIterator<CommonVariantFieldClass>;
 
     using Option =
-        typename std::conditional<std::is_const<LibObjT>::value, ConstVariantFieldClassOption,
-                                  VariantFieldClassOption>::type;
-
-    using Iterator = CommonIterator<CommonVariantFieldClass, Option>;
+        internal::DepType<LibObjT, VariantFieldClassOption, ConstVariantFieldClassOption>;
 
     explicit CommonVariantFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonFieldClass {libObjPtr}
@@ -2122,19 +2148,24 @@ public:
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT>& fc) noexcept :
+    CommonVariantFieldClass(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantFieldClass& operator=(const CommonVariantFieldClass<OtherLibObjT>& fc) noexcept
+    CommonVariantFieldClass operator=(const CommonVariantFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonFieldClass::operator=(fc);
         return *this;
     }
 
-    std::uint64_t size() const noexcept
+    CommonVariantFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonVariantFieldClass<const bt_field_class> {*this};
+    }
+
+    std::uint64_t length() const noexcept
     {
         return bt_field_class_variant_get_option_count(this->libObjPtr());
     }
@@ -2146,43 +2177,16 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
-    ConstVariantFieldClassOption operator[](const std::uint64_t index) const noexcept
-    {
-        return ConstVariantFieldClassOption {
-            internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByIndex(
-                this->libObjPtr(), index)};
-    }
-
-    Option operator[](const std::uint64_t index) noexcept
+    Option operator[](const std::uint64_t index) const noexcept
     {
         return Option {internal::CommonVariantFieldClassSpec<LibObjT>::optionByIndex(
             this->libObjPtr(), index)};
     }
 
-    nonstd::optional<ConstVariantFieldClassOption>
-    operator[](const char * const name) const noexcept
-    {
-        const auto libObjPtr =
-            internal::CommonVariantFieldClassSpec<const bt_field_class>::optionByName(
-                this->libObjPtr(), name);
-
-        if (libObjPtr) {
-            return ConstVariantFieldClassOption {libObjPtr};
-        }
-
-        return nonstd::nullopt;
-    }
-
-    nonstd::optional<ConstVariantFieldClassOption>
-    operator[](const std::string& name) const noexcept
-    {
-        return (*this)[name.data()];
-    }
-
-    nonstd::optional<Option> operator[](const char * const name) noexcept
+    bt2s::optional<Option> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr =
             internal::CommonVariantFieldClassSpec<LibObjT>::optionByName(this->libObjPtr(), name);
@@ -2191,10 +2195,10 @@ public:
             return Option {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Option> operator[](const std::string& name) noexcept
+    bt2s::optional<Option> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
@@ -2236,8 +2240,7 @@ private:
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
 
 public:
-    using Shared =
-        internal::SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
+    using Shared = SharedFieldClass<CommonVariantWithoutSelectorFieldClass<LibObjT>, LibObjT>;
 
     explicit CommonVariantWithoutSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantFieldClass {libObjPtr}
@@ -2247,35 +2250,41 @@ public:
 
     template <typename OtherLibObjT>
     CommonVariantWithoutSelectorFieldClass(
-        const CommonVariantWithoutSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+        const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonVariantFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithoutSelectorFieldClass&
-    operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT>& fc) noexcept
+    CommonVariantWithoutSelectorFieldClass
+    operator=(const CommonVariantWithoutSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonVariantFieldClass::operator=(fc);
         return *this;
     }
 
-    void appendOption(const char * const name, const FieldClass& fc)
+    CommonVariantWithoutSelectorFieldClass<const bt_field_class> asConst() const noexcept
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        return CommonVariantWithoutSelectorFieldClass<const bt_field_class> {*this};
+    }
+
+    void appendOption(const char * const name, const FieldClass fc) const
+    {
+        static_assert(!std::is_const<LibObjT>::value,
+                      "Not available with `bt2::ConstVariantWithoutSelectorFieldClass`.");
 
         const auto status = bt_field_class_variant_without_selector_append_option(
             this->libObjPtr(), name, fc.libObjPtr());
 
         if (status ==
             BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
-    void appendOption(const std::string& name, const FieldClass& fc)
+    void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc) const
     {
-        this->appendOption(name.data(), fc);
+        this->appendOption(name ? name->data() : nullptr, fc);
     }
 
     Shared shared() const noexcept
@@ -2384,7 +2393,7 @@ protected:
     using _ThisCommonVariantWithSelectorFieldClass = CommonVariantWithSelectorFieldClass<LibObjT>;
 
 public:
-    using Shared = internal::SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
+    using Shared = SharedFieldClass<_ThisCommonVariantWithSelectorFieldClass, LibObjT>;
 
     explicit CommonVariantWithSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantFieldClass {libObjPtr}
@@ -2394,19 +2403,24 @@ public:
 
     template <typename OtherLibObjT>
     CommonVariantWithSelectorFieldClass(
-        const CommonVariantWithSelectorFieldClass<OtherLibObjT>& fc) noexcept :
+        const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept :
         _ThisCommonVariantFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithSelectorFieldClass&
-    operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT>& fc) noexcept
+    CommonVariantWithSelectorFieldClass
+    operator=(const CommonVariantWithSelectorFieldClass<OtherLibObjT> fc) noexcept
     {
         _ThisCommonVariantFieldClass::operator=(fc);
         return *this;
     }
 
+    CommonVariantWithSelectorFieldClass<const bt_field_class> asConst() const noexcept
+    {
+        return CommonVariantWithSelectorFieldClass<const bt_field_class> {*this};
+    }
+
     ConstFieldPath selectorFieldPath() const noexcept
     {
         return ConstFieldPath {
@@ -2432,18 +2446,15 @@ private:
     using typename CommonVariantWithSelectorFieldClass<
         LibObjT>::_ThisCommonVariantWithSelectorFieldClass;
     using typename CommonFieldClass<LibObjT>::_LibObjPtr;
-    using _ThisCommonVariantWithIntegerSelectorFieldClass =
-        CommonVariantWithIntegerSelectorFieldClass<LibObjT, OptionT>;
 
     using _Spec = internal::CommonVariantWithIntegerSelectorFieldClassSpec<OptionT>;
 
 public:
-    using Shared =
-        internal::SharedFieldClass<_ThisCommonVariantWithIntegerSelectorFieldClass, LibObjT>;
-
+    using Shared = SharedFieldClass<CommonVariantWithIntegerSelectorFieldClass, LibObjT>;
     using Option = OptionT;
+
     using Iterator =
-        CommonIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>, Option>;
+        BorrowedObjectIterator<CommonVariantWithIntegerSelectorFieldClass<LibObjT, Option>>;
 
     explicit CommonVariantWithIntegerSelectorFieldClass(const _LibObjPtr libObjPtr) noexcept :
         _ThisCommonVariantWithSelectorFieldClass {libObjPtr}
@@ -2453,14 +2464,14 @@ public:
 
     template <typename OtherLibObjT>
     CommonVariantWithIntegerSelectorFieldClass(
-        const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT>& fc) noexcept :
+        const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept :
         _ThisCommonVariantWithSelectorFieldClass {fc}
     {
     }
 
     template <typename OtherLibObjT>
-    CommonVariantWithIntegerSelectorFieldClass&
-    operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT>& fc) noexcept
+    CommonVariantWithIntegerSelectorFieldClass
+    operator=(const CommonVariantWithIntegerSelectorFieldClass<OtherLibObjT, OptionT> fc) noexcept
     {
         _ThisCommonVariantWithSelectorFieldClass::operator=(fc);
         return *this;
@@ -2471,7 +2482,7 @@ public:
         return Option {_Spec::optionByIndex(this->libObjPtr(), index)};
     }
 
-    nonstd::optional<Option> operator[](const char * const name) const noexcept
+    bt2s::optional<Option> operator[](const char * const name) const noexcept
     {
         const auto libObjPtr = _Spec::optionByName(this->libObjPtr(), name);
 
@@ -2479,31 +2490,34 @@ public:
             return Option {libObjPtr};
         }
 
-        return nonstd::nullopt;
+        return bt2s::nullopt;
     }
 
-    nonstd::optional<Option> operator[](const std::string& name) const noexcept
+    bt2s::optional<Option> operator[](const std::string& name) const noexcept
     {
         return (*this)[name.data()];
     }
 
-    void appendOption(const char * const name, const FieldClass& fc,
-                      const typename Option::RangeSet& ranges)
+    void appendOption(const char * const name, const FieldClass fc,
+                      const typename Option::RangeSet ranges) const
     {
-        static_assert(!std::is_const<LibObjT>::value, "`LibObjT` must NOT be `const`.");
+        static_assert(
+            !std::is_const<LibObjT>::value,
+            "Not available with `bt2::ConstVariantWithUnsignedIntegerSelectorFieldClass`.");
 
         const auto status =
             _Spec::appendOption(this->libObjPtr(), name, fc.libObjPtr(), ranges.libObjPtr());
 
         if (status ==
             BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_MEMORY_ERROR) {
-            throw LibMemoryError {};
+            throw MemoryError {};
         }
     }
 
-    void appendOption(const std::string& name, const FieldClass& fc)
+    void appendOption(const bt2s::optional<std::string>& name, const FieldClass fc,
+                      const typename Option::RangeSet ranges) const
     {
-        this->appendOption(name.data(), fc);
+        this->appendOption(name ? name->data() : nullptr, fc, ranges);
     }
 
     Iterator begin() const noexcept
@@ -2513,7 +2527,7 @@ public:
 
     Iterator end() const noexcept
     {
-        return Iterator {*this, this->size()};
+        return Iterator {*this, this->length()};
     }
 
     Shared shared() const noexcept
This page took 0.044677 seconds and 4 git commands to generate.