Skip to content

Conversation

@chriseth
Copy link
Contributor

@chriseth chriseth commented Jun 1, 2021

No description provided.

std::multimap<std::string, FunctionDefinition const*> const& functions = m_definedFunctionsByName.init([&]{
std::multimap<std::string, FunctionDefinition const*> result;
for (FunctionDefinition const* fun: filteredNodes<FunctionDefinition>(m_subNodes))
result.insert({fun->name(), fun});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionDefinition is only forward-declared here.

@chriseth chriseth force-pushed the cacheVirtualLookup branch 2 times, most recently from 45a7d83 to 4bc76cb Compare June 1, 2021 13:17
auto definedFunctions(std::string const& _name) const {
auto&& [b, e] = definedFunctionsByName().equal_range(_name);
return ranges::span<decltype(*b)>(b, e) | ranges::views::transform([](auto const& _item) { return _item.second; });
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekpyron is that you

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what we wrote about in the chat earlier :-).
I think it has to be

return ranges::subrange(b, e) | ranges::views::values;

to work.

std::vector<ModifierDefinition const*> functionModifiers() const { return filteredNodes<ModifierDefinition>(m_subNodes); }
std::vector<FunctionDefinition const*> definedFunctions() const { return filteredNodes<FunctionDefinition>(m_subNodes); }
auto definedFunctions() const {
return definedFunctionsByName() | ranges::views::transform([](auto const& _item) { return _item.second; });
Copy link

@leonardoalt leonardoalt Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return definedFunctionsByName() | ranges::views::transform([](auto const& _item) { return _item.second; });
return definedFunctionsByName() | ranges::views::values;

does that work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should work, when including <range/v3/view/map.hpp> and is nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, but it doesn't - it's a multimap - d'oh!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No really, I'm underwhelmed by the power of that library.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does work for me for a multimap :-).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least this:

#include <range/v3/all.hpp>
#include <iostream>
#include <map>

int main()
{

        std::multimap<int, int> x{{1,1},{2,3},{2,4}};
        auto r = x | ranges::views::values;
        for (auto v : r)
                std::cout << v << std::endl;
        std::cout << std::endl;

        auto&& [b,e] = x.equal_range(2);
        auto r2 = ranges::subrange(b,e) | ranges::views::values;
        for (auto v : r2)
                std::cout << v << std::endl;
}

compiles just fine for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird...

@chriseth chriseth force-pushed the cacheVirtualLookup branch 3 times, most recently from 2bb0ae0 to 165d540 Compare June 2, 2021 07:18
@chriseth
Copy link
Contributor Author

chriseth commented Jun 2, 2021

Tests fail because the order of iteration is different. I think it would be good to preserve it - I'll think about it.

Copy link
Collaborator

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the iteration order question, this looks good to me apart from superfluous headers.

Comment on lines 32 to 34
#include <range/v3/view/map.hpp>
#include <range/v3/span.hpp>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither are needed here anymore, are they?


#include <range/v3/view/subrange.hpp>
#include <range/v3/view/map.hpp>
#include <range/v3/view/transform.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform isn't needed anymore, is it?

@ekpyron
Copy link
Collaborator

ekpyron commented Jun 2, 2021

Regarding the order: Since C++11 the standard dictates The order of the key-value pairs whose keys compare equivalent is the order of insertion and does not change.... with different keys the sorting is of course per name, though, but not sure that's too bad.

And I don't think there will be a way to have efficient lookup by name without sorting by name.

@chriseth chriseth force-pushed the cacheVirtualLookup branch 2 times, most recently from 1aaaae8 to b9d4158 Compare June 2, 2021 10:43
ekpyron
ekpyron previously approved these changes Jun 2, 2021
ekpyron
ekpyron previously approved these changes Jun 3, 2021
Copy link
Collaborator

@ekpyron ekpyron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs rebase, apart from that still approved.

@ekpyron ekpyron enabled auto-merge June 3, 2021 09:12
@ekpyron ekpyron merged commit 9be5754 into develop Jun 3, 2021
@ekpyron ekpyron deleted the cacheVirtualLookup branch June 3, 2021 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants