include/frozen/map.h:114:12: error: binding reference of type 'int' to value of type 'const int' drops 'const' qualifier
nbrachet opened this issue · 2 comments
nbrachet commented
The following code snippet used to work (at least in git hash c5bfada) but now fails:
#include <string>
#include <frozen/string.h>
#include <frozen/map.h>
void foo(const std::string& s, int& i)
{
static constexpr frozen::map<frozen::string, int, 2> MAP = {
{ "one", 1 },
{ "two", 2 }
};
i = MAP.at(frozen::string{s.data(), s.length()});
}
int main()
{
int i;
foo("one", i);
}
with the following error:
In file included from <source>:5:
.../frozen/include/frozen/map.h:114:12: error: binding reference of type 'int' to value of type 'const int' drops 'const' qualifier
return at_impl(*this, key);
^~~~~~~~~~~~~~~~~~~
<source>:14:13: note: in instantiation of member function 'frozen::map<frozen::basic_string<char>, int, 2, std::__1::less<frozen::basic_string<char> > >::at' requested here
i = MAP.at(frozen::string{s.data(), s.length()});
^
1 error generated.
Compiler returned: 1
Compiler: clang++ --std=c++14
OS: MacOS 10.15
nbrachet commented
The following looks it resolves the issue:
--- a/include/frozen/map.h
+++ b/include/frozen/map.h
@@ -110,7 +110,7 @@ public:
: map{items, Compare{}} {}
/* element access */
- constexpr Value& at(Key const &key) const {
+ constexpr Value const& at(Key const &key) const {
return at_impl(*this, key);
}
constexpr Value& at(Key const &key) {
serge-sans-paille commented
gotcha! Feel free to submit a PR (and add a testcase?)