Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::vector<bool, Alloc>::reference

      From cppreference.com
      <cpp‎ |container‎ |vector bool
       
       
       
      std::vector<bool>
      Member types
      vector<bool>::reference
      Member functions
      Non-member functions
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
      Helper classes
      Deduction guides(C++17)
       
      class reference;

      Thestd::vector<bool, Alloc> specializations definestd::vector<bool, Alloc>::reference as a publicly-accessible nested class.std::vector<bool, Alloc>::reference proxies the behavior of references to a single bit instd::vector<bool, Alloc>.

      The primary use ofstd::vector<bool, Alloc>::reference is to provide an assignable value that can be returned fromoperator[].

      Any reads or writes to a vector that happen via astd::vector<bool, Alloc>::reference potentially read or write to the entire underlying vector.

      Contents

      [edit]Member functions

      (constructor)
      constructs the reference
      (public member function)
      (destructor)
      destroys the reference
      (public member function)
      operator=
      assigns a value to the referenced bit
      (public member function)
      operator bool
      returns the referenced bit
      (public member function)[edit]
      flip
      flips the referenced bit
      (public member function)

      std::vector<bool, Alloc>::reference::reference

      reference(const reference&)=default;
      (since C++11)
      (constexpr since C++20)

      Constructs the reference from another reference. The copy constructor is implicitly declared.(until C++11)

      Other constructors can only be accessed bystd::vector<bool, Alloc>.

      std::vector<bool, Alloc>::reference::~reference

      ~reference();
      (constexpr since C++20)

      Destroys the reference.

      std::vector<bool, Alloc>::reference::operator=

      reference& operator=(bool x);
      (1)(noexcept since C++11)
      (constexpr since C++20)
      constexprconst reference& operator=(bool x)constnoexcept;
      (2)(since C++23)
      reference& operator=(const reference& x);
      (3)(noexcept since C++11)
      (constexpr since C++20)

      Assigns a value to the referenced bit.

      The constoperator= enablesstd::vector<bool,Alloc>::iterator to satisfyoutput_iterator.

      (since C++23)

      Parameters

      x - value to assign

      Return value

      *this

      std::vector<bool, Alloc>::reference::operator bool

      operatorbool()const;
      (noexcept since C++11)
      (constexpr since C++20)

      Returns the value of the referenced bit.

      Return value

      The referenced bit.

      std::vector<bool, Alloc>::reference::flip

      void flip();
      (noexcept since C++11)
      (constexpr since C++20)

      Inverts the referenced bit.

      [edit]Helper classes

      std::formatter<std::vector<bool, Alloc>::reference>

      template<class T,class CharT>

        requires/*is-vector-bool-reference*/<T>

      struct formatter<T, CharT>;
      (since C++23)

      Specializes thestd::formatter forstd::vector<bool, Alloc>::reference. The specialization usesstd::formatter<bool, CharT> as its underlying formatter (denoted asunderlying_) where the referenced bit is converted tobool to be formatted.

      The exposition-only constant/*is-vector-bool-reference*/<T> istrue if and only ifT denotes the typestd::vector<bool, Alloc>::reference for some typeAlloc andstd::vector<bool, Alloc> is not aprogram-defined specialization.

      Member functions

      template<class ParseContext>
      constexpr ParseContext::iterator parse( ParseContext& ctx);
      (1)(since C++23)
      template<class FormatContext>
      FormatContext::iterator format(const T& r, FormatContext& ctx)const;
      (2)(since C++23)
      1) Equivalent toreturn underlying_.parse(ctx);.
      2) Equivalent toreturn underlying_.format(r, ctx);.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      access specified element
      (public member function ofstd::vector<T,Allocator>)[edit]
      [static]
      swaps twostd::vector<bool>::references
      (public static member function)[edit]

      [edit]External links

      "Effective Modern C++" by Scott Meyers (2015), Chapter 2, Item 6: "Use the explicitly typed initializer idiom whenauto deduces undesired types." (p.43-46) — describes a possible misuse of the proxy classstd::vector<bool>::reference).
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/vector_bool/reference&oldid=182905"

      [8]ページ先頭

      ©2009-2025 Movatter.jp