TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24167 18
Using concepts to differentiate which template function to call - is it allowed?

I have two template functions that:

* have the same name
* have different type for the first nontype template argument
* both have a second type argument, deduced from the regular argument, with a different constraint. The constraint fully differentiate between allowed types (there is no overlap)

When I call the function, the compiler is unable to differentiate the functions based on the nontype template argument. I expect it to then use the constraint of the second template argument to figure out which function should be used.

If the above description is too vague, here is a concrete, minimal example:

[https://godbolt.org/z/Koc89coWY](https://godbolt.org/z/Koc89coWY)

gcc and clang are able to figure it out. MSVC is not.

But is it actually expected from the compiler? Or am I relying on some extra capability of gcc/clang?

If it is the former, is there a way to make MSVC work with it, while keeping the same function name?

https://redd.it/1ompyhp
@r_cpp
godbolt.org Compiler Explorer - C++ struct I2 { int x; int y; }; struct Foo { int x; }; template<typename T> concept FooKind = std::same_as<T, Foo>; struct Bar { int x; int y; }; template<typename T> concept BarKind = std::same_as<T, Bar>; template<int Idx, FooKind…
More from @r_cpp
  1. Oct 12, 2026[Release] slick-logger v2.2.0 — Lock-free asynchronous C++20 logging with multi-process sh…
  2. Oct 12, 2026Cheap alternative to reboot parameters (nohz, rcu, isolcpus) for stable benchmarks When no…
  3. Oct 12, 2026This C++ drama is crazy - Adobe votes no https://www.youtube.com/watch?v=DEqx_NMMH9Q https…
  4. Oct 12, 2026FastNoise2: noise generation using SIMD and C++17 https://github.com/Auburn/FastNoise2 htt…
  5. Oct 12, 2026New C++ Conference Videos Released This Month - October 2026 (Updated To Include Videos Re…
  6. Oct 12, 2026cxvm: pin a GCC or Clang version per project on Linux (pyenv/nvm, but for C++ compilers) I…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →