[GELÖST] std::map mit nicht kopierbarem Schlüssel-Typ?



  • Betrachte bitte folgenden Quellcode:

    #include <map>
    
    struct movable_key_type
    {
        int key_thing;
    
        inline movable_key_type( void ) {}
        inline movable_key_type( movable_key_type&& right ) { this->key_thing = right.key_thing; }
        inline movable_key_type( const movable_key_type& right ) = delete;
    
        inline movable_key_type& operator = ( movable_key_type&& right )
        {
            this->~movable_key_type();
    
            return *new (this) movable_key_type( std::move( right ) );
        }
        inline movable_key_type& operator = ( const movable_key_type& right ) = delete;
    
        inline bool operator < ( const movable_key_type& right ) const
        {
            return ( this->key_thing < right.key_thing );
        }
    };
    
    int main( int argc, char *argv[] )
    {
        std::map <movable_key_type, int> test_map;
        std::map <movable_key_type, int> test_map_2;
    
        test_map = std::move( test_map_2 );
    
        return 0;
    }
    

    Dieser Quellcode scheint unter Visual Studio 2017 zu kompilieren. Allerdings spuckt mir GCC/G++ eine sehr lange Fehlermeldung aus.
    Das ist schlecht wenn man seinen Code auf Linux zum Laufen bringen will 🙄

    Fehler scheint sich (nach Probe-Auskommentieren) in der Zeile zu befinden...

    test_map = std::move( test_map_2 );
    

    Auszug aus G++ Fehlerlog:

    /usr/include/c++/5/ext/new_allocator.h:120:4: error: use of deleted function ‘constexpr std::pair<_T1, _T2>::pair(std::pair<_T1, _T2>&&) [with _T1 = const movable_key_type; _T2 = int]’
    

    Hier sind die Baudateien, die ich verwendet habe:
    https://www.file-upload.net/download-12659159/defects.zip.html

    Bitte um Hilfe!



  • Mit GCC 7 kompiliert es. Vermutlich handelt es sich um einen Bug in älteren Versionen von libstdc++.



  • @zerg: Habe den Code mit GCC 5.4.0 kompiliert. Diese Version ist standardmäßig auf Ubuntu 16.04 (LTS) installiert. Sollte wohl upgraden ^^

    Danke für den Hinweis!


Anmelden zum Antworten