Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTAD issue using frozen::map #168

Open
pfee opened this issue Dec 20, 2023 · 1 comment
Open

CTAD issue using frozen::map #168

pfee opened this issue Dec 20, 2023 · 1 comment

Comments

@pfee
Copy link

pfee commented Dec 20, 2023

I'm unable to use class template argument deduction with frozen::map and frozen::unordered_map. I'm able to use it with std::map and std::unordered_map.

Is this a bug with the frozen library or an issue with my code?

$ cat deduction.cpp 
#include <frozen/set.h>
#include <frozen/map.h>
#include <cstdint> // pmh.h missing include fixed after 1.1.1 was released.
#include <frozen/unordered_map.h>
#include <string_view>
#include <set>
#include <map>
#include <unordered_map>

using namespace std::literals;

int main()
{
    std::set a = {"one"sv, "two"sv};
    frozen::set b = {"one"sv, "two"sv};
    std::map c = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}};
    // frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
    std::unordered_map e = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}};
    // frozen::unordered_map f = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error

    return 0;
}

I've tried compiling with v1.1.1 and with the latest (7e79c37) from git. Both fail in the same way.

Environment:

  • openSUSE Tumbleweed
  • GCC 13.2.1
  • C++17

My primary reason for wanting to use CTAD is to avoid having to specify the size of the container, which can be awkward with large datasets.

@pfee
Copy link
Author

pfee commented Dec 20, 2023

Example compilation error:

$ c++ deduction.cpp 
deduction.cpp: In function ‘int main()’:
deduction.cpp:17:66: error: class template argument deduction failed:
   17 |     frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
      |                                                                  ^
deduction.cpp:17:66: error: no matching function for call to ‘map(std::pair<std::basic_string_view<char>, int>, std::pair<std::basic_string_view<char>, int>)’
In file included from deduction.cpp:2:
/usr/include/frozen/map.h:109:13: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(std::initializer_list<typename frozen::bits::carray<std::pair<_T1, _T2>, N>::value_type>)-> frozen::map<Key, Value, N, Compare>’
  109 |   constexpr map(std::initializer_list<value_type> items)
      |             ^~~
/usr/include/frozen/map.h:109:13: note:   template argument deduction/substitution failed:
deduction.cpp:17:66: note:   candidate expects 1 argument, 2 provided
   17 |     frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
      |                                                                  ^
/usr/include/frozen/map.h:104:13: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(std::initializer_list<typename frozen::bits::carray<std::pair<_T1, _T2>, N>::value_type>, const Compare&)-> frozen::map<Key, Value, N, Compare>’
  104 |   constexpr map(std::initializer_list<value_type> items, Compare const &compare)
      |             ^~~
/usr/include/frozen/map.h:104:13: note:   template argument deduction/substitution failed:
deduction.cpp:17:66: note:   couldn’t deduce template parameter ‘Key’
   17 |     frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
      |                                                                  ^
/usr/include/frozen/map.h:101:22: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(frozen::bits::carray<std::pair<_T1, _T2>, N>)-> frozen::map<Key, Value, N, Compare>’
  101 |   explicit constexpr map(container_type items)
      |                      ^~~
/usr/include/frozen/map.h:101:22: note:   template argument deduction/substitution failed:
deduction.cpp:17:66: note:   ‘std::pair<std::basic_string_view<char>, int>’ is not derived from ‘frozen::bits::carray<std::pair<_T1, _T2>, N>’
   17 |     frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
      |                                                                  ^
/usr/include/frozen/map.h:97:13: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(frozen::bits::carray<std::pair<_T1, _T2>, N>, const Compare&)-> frozen::map<Key, Value, N, Compare>’
   97 |   constexpr map(container_type items, Compare const &compare)
      |             ^~~
/usr/include/frozen/map.h:97:13: note:   template argument deduction/substitution failed:
deduction.cpp:17:66: note:   ‘std::pair<std::basic_string_view<char>, int>’ is not derived from ‘frozen::bits::carray<std::pair<_T1, _T2>, N>’
   17 |     frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
      |                                                                  ^
/usr/include/frozen/map.h:73:7: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(frozen::map<Key, Value, N, Compare>)-> frozen::map<Key, Value, N, Compare>’
   73 | class map {
      |       ^~~
/usr/include/frozen/map.h:73:7: note:   template argument deduction/substitution failed:
deduction.cpp:17:66: note:   ‘std::pair<std::basic_string_view<char>, int>’ is not derived from ‘frozen::map<Key, Value, N, Compare>’
   17 |     frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
      |

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

No branches or pull requests

1 participant