Skip to content

std::map can no longer be iterated over with pairs #1742

@nimble0

Description

@nimble0

Example:

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>

#include <iostream>
#include <map>

int main(int, char**) {
	sol::state lua;
	lua.open_libraries();

	std::map<int, std::string> myMap
	{
		{3, "three"},
		{10, "ten"},
		{5, "five"},
	};

	std::cout << "cpp iteration:" << std::endl;
	for(auto& kv : myMap)
		std::cout << kv.first << ": " << kv.second << "\n";
	std::cout << std::endl;

	lua["myMap"] = myMap;
	lua["myMap2"] = sol::as_table(myMap);

	lua.script(R"(

print("lua myMap iteration:")
for k, v in pairs(myMap) do
	print(k, ":", v)
end
print()

print("lua sol::as_table(myMap) iteration:")
for k, v in pairs(myMap2) do
	print(k, ":", v)
end
print()

	)");

	return 0;
}

Output:

cpp iteration:
3: three
5: five
10: ten

lua myMap iteration:

lua sol::as_table(myMap) iteration:
3	:	three
10	:	ten
5	:	five

This was introduced in 64e3823.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions