vendredi 21 octobre 2022

Why does an argument type of std::set accept {} as argumet but boost::container::flat_set does not?

I converted some methods from argument type const std::set<>& to const boost::container::flat_set<>& with the same template types being passed. Now I have to change every occurrence of calls to these methods where the argument was {} and have to replace them with typename().

Why is this and is there some easier way?

boost_1_60_0 being used -- don't blame me!

To compile

g++ -std=c++11 test_set.cpp -D__FLAT__

or

g++ -std=c++11 test_set.cpp

The error message is clear -- and I couldn't read the original.

I guess the {} can only be interpreted as argument list, as the type is unknown.

#include <set>
#include <map>
#include <boost/container/flat_set.hpp>
#include <boost/container/flat_map.hpp>

#ifndef __FLAT__
typedef std::map<int, int> MAP;
typedef std::set<MAP> SET;
#else
typedef boost::container::flat_map<int, int> MAP;
typedef boost::container::flat_set<MAP> SET;
#endif


static void show(const SET&)
{
}
int main(int, char**)
{   

    //SET s({});
    show({});
}

example:

Aucun commentaire:

Enregistrer un commentaire