Unable to create unordered_set with lambda function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
1












I get the error



error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at 
main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()


with the following code. What's the mistake I am making and I couldn't understand the error as well.



using namespace std;

auto my_hash = (vector<int> const& vec)
size_t seed = vec.size();
for(auto& i : vec)
seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

return seed;
;

using MySet = unordered_set<vector<int>, decltype(my_hash)>;

int main()
vector<int> a1,2,3;
MySet s;
return 0;










share|improve this question

























    up vote
    6
    down vote

    favorite
    1












    I get the error



    error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at 
    main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()


    with the following code. What's the mistake I am making and I couldn't understand the error as well.



    using namespace std;

    auto my_hash = (vector<int> const& vec)
    size_t seed = vec.size();
    for(auto& i : vec)
    seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

    return seed;
    ;

    using MySet = unordered_set<vector<int>, decltype(my_hash)>;

    int main()
    vector<int> a1,2,3;
    MySet s;
    return 0;










    share|improve this question























      up vote
      6
      down vote

      favorite
      1









      up vote
      6
      down vote

      favorite
      1






      1





      I get the error



      error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at 
      main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()


      with the following code. What's the mistake I am making and I couldn't understand the error as well.



      using namespace std;

      auto my_hash = (vector<int> const& vec)
      size_t seed = vec.size();
      for(auto& i : vec)
      seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

      return seed;
      ;

      using MySet = unordered_set<vector<int>, decltype(my_hash)>;

      int main()
      vector<int> a1,2,3;
      MySet s;
      return 0;










      share|improve this question













      I get the error



      error: call to implicitly-deleted default constructor of '__compressed_pair_elem<(lambda at 
      main.cpp:181:16), 1>': _Base1(std::forward<_Tp>(__t)), _Base2()


      with the following code. What's the mistake I am making and I couldn't understand the error as well.



      using namespace std;

      auto my_hash = (vector<int> const& vec)
      size_t seed = vec.size();
      for(auto& i : vec)
      seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

      return seed;
      ;

      using MySet = unordered_set<vector<int>, decltype(my_hash)>;

      int main()
      vector<int> a1,2,3;
      MySet s;
      return 0;







      c++ c++11 c++14






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 26 mins ago









      user3285099

      627




      627






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          10
          down vote













          Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:



          constexpr std::size_t bucket_count = 512;
          MySet sbucket_count, my_hash;


          live example on wandbox.org




          Alternatively, you can use a good old struct:



          struct Hasher 
          auto operator()(vector<int> const& vec) const
          size_t seed = vec.size();
          for(auto& i : vec)
          seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

          return seed;

          ;

          using MySet = unordered_set<vector<int>, Hasher>;

          int main()
          MySet s;



          live example on wandbox.org






          share|improve this answer






















            Your Answer





            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53045494%2funable-to-create-unordered-set-with-lambda-function%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            10
            down vote













            Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:



            constexpr std::size_t bucket_count = 512;
            MySet sbucket_count, my_hash;


            live example on wandbox.org




            Alternatively, you can use a good old struct:



            struct Hasher 
            auto operator()(vector<int> const& vec) const
            size_t seed = vec.size();
            for(auto& i : vec)
            seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

            return seed;

            ;

            using MySet = unordered_set<vector<int>, Hasher>;

            int main()
            MySet s;



            live example on wandbox.org






            share|improve this answer


























              up vote
              10
              down vote













              Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:



              constexpr std::size_t bucket_count = 512;
              MySet sbucket_count, my_hash;


              live example on wandbox.org




              Alternatively, you can use a good old struct:



              struct Hasher 
              auto operator()(vector<int> const& vec) const
              size_t seed = vec.size();
              for(auto& i : vec)
              seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

              return seed;

              ;

              using MySet = unordered_set<vector<int>, Hasher>;

              int main()
              MySet s;



              live example on wandbox.org






              share|improve this answer
























                up vote
                10
                down vote










                up vote
                10
                down vote









                Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:



                constexpr std::size_t bucket_count = 512;
                MySet sbucket_count, my_hash;


                live example on wandbox.org




                Alternatively, you can use a good old struct:



                struct Hasher 
                auto operator()(vector<int> const& vec) const
                size_t seed = vec.size();
                for(auto& i : vec)
                seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

                return seed;

                ;

                using MySet = unordered_set<vector<int>, Hasher>;

                int main()
                MySet s;



                live example on wandbox.org






                share|improve this answer














                Closure types are not default-constructible prior to C++20 (see P0624). You need to pass in an instance of your hasher:



                constexpr std::size_t bucket_count = 512;
                MySet sbucket_count, my_hash;


                live example on wandbox.org




                Alternatively, you can use a good old struct:



                struct Hasher 
                auto operator()(vector<int> const& vec) const
                size_t seed = vec.size();
                for(auto& i : vec)
                seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);

                return seed;

                ;

                using MySet = unordered_set<vector<int>, Hasher>;

                int main()
                MySet s;



                live example on wandbox.org







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 21 mins ago

























                answered 24 mins ago









                Vittorio Romeo

                54.3k16140282




                54.3k16140282



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53045494%2funable-to-create-unordered-set-with-lambda-function%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery