Ordnungsgemäße Unterstützung des volatilen Qualifikators der Mitgliederfunktionen in STLC++

Programme in C++. Entwicklerforum
Anonymous
 Ordnungsgemäße Unterstützung des volatilen Qualifikators der Mitgliederfunktionen in STL

Post by Anonymous »

Unsachgemäße Unterstützung von volatil-qualifizierten Überladungen von Mitgliederfunktionen in stl verhindert die Verwendung von Containern, intelligenten Zeigern usw. in Generic Code. Sagen Sie, ich möchte eine Wrapper -Klasse deklarieren, die Wertsemantik liefert und die zugrunde liegende Typen zu ermöglichen: < /p>

Code: Select all

#include 
#include 
#include 

template< typename type >
struct recursive_wrapper
{

using value_type = type;

template< typename ...arguments >
recursive_wrapper(arguments &&... _arguments)
: storage_(std::make_unique< type >(std::forward< arguments >(_arguments)...))
{ ; }

operator type & () & noexcept
{
return *storage_;
}

operator type const & () const & noexcept
{
return *storage_;
}

operator type && () && noexcept
{
return std::move(*storage_);
}

operator type const && () const && noexcept
{
return std::move(*storage_);
}

operator volatile type & () volatile & noexcept
{
return *storage_;
}

operator volatile type const & () volatile const & noexcept
{
return *storage_;
}

operator volatile type && () volatile && noexcept
{
return std::move(*storage_);
}

operator volatile type const && () volatile const && noexcept
{
return std::move(*storage_);
}

private :

std::unique_ptr< type > storage_;

};

// file:main.cpp
#include 
#include 

#include 

int
main()
{
struct A;
struct B { recursive_wrapper< A > a; };
struct A { std::vector< B > b; };
{ // basic usage
B b;
A & a = b.a; // OK
static_cast< void >(a);
}
// let's add cv-qualifiers
{
volatile B b;
volatile A & a = b.a; // error!
static_cast< void >(a);
}
return EXIT_SUCCESS;
}
Mangel an geeignetem volatil-qualifiziert Überlastung von std :: unqie_ptr :: operator * () verursacht einen Fehler:

Code: Select all

main.cpp:38:16: error: indirection requires pointer operand ('volatile std::unique_ptr' invalid)
return *storage_;
^~~~~~~~~
main.cpp:83:30: note: in instantiation of member function 'recursive_wrapper::operator volatile A &' requested here
volatile A & a = b.a;
^
Die gleiche Geschichte mit std :: container :: push_back () , size () usw. Warum wird in stl nicht ordnungsgemäß unterstützt Mitgliedsfunktionsfunktion? Ist die volatile Mitgliedsfunktion Qualifikant veraltet?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post