0

In C++11 it is not possible to partially specialize member functions independent of the containing class, as noted here: c++ template partial specialization member function

My question: is this likely to change? Are there proposals in the pipeline to fix this shortcoming?

Community
  • 1
  • 1
Ross Bencina
  • 3,822
  • 1
  • 19
  • 33
  • 1
    I don't think it's ever likely to change. Some longer answer [here](http://stackoverflow.com/questions/13923684/template-class-incomplete-specialization). – StoryTeller - Unslander Monica Dec 12 '16 at 08:17
  • 1
    I don't know if there is such a proposal, but even if there is, it doesn't look like it's in the spotlight. In C++17 you can use constexpr if a new alternative to member specialization. – bolov Dec 12 '16 at 08:19
  • It's not likely as it could lead to too many problems if suddenly you have incompatible types between the member function and member variables? – Some programmer dude Dec 12 '16 at 08:21
  • It's not needed. Template functions can implement themselves in terms of partially specialised function objects. – Richard Hodges Dec 12 '16 at 08:44
  • RichardHodges: Template functions perhaps, but template member functions not so easily. – Ross Bencina Dec 12 '16 at 09:05
  • @RossBencina post some code that you think needs partial specialisation of member functions and I'll show you why you don't need it. – Richard Hodges Dec 12 '16 at 09:19
  • You could use templated structs with partial specialization to work around this problem: https://godbolt.org/g/nmyRAq but usually you don't really need it. – Simon Kraemer Dec 12 '16 at 09:35
  • @RichardHodges: when you say "don't need it" do you mean "I know a workaround"? Because I know a few workarounds too, but that doesn't change the fact that when I mean "partially specialize" I want to actually write it in the language. – Ross Bencina Dec 12 '16 at 09:48
  • @RossBencina no, I really mean "you don't need it". ADL provides almost the same functionality, and if you really need partial specialisation you can do it via a helper class. In fact I would go further and say that a well written program or library will never specialise a function. – Richard Hodges Dec 12 '16 at 10:24
  • @RichardHodges I see what you mean. However when mixing templates and ADL I would prefer to express everything with one mechanism (partial specialization) than to mix overloading (for the specialized params) and templates (for the generic params). Also, I'm working with type-level values, so I usually need the full type for the generic parameters, I can't always use a tag-dispatch style specialization hierarchy because that drops type information. – Ross Bencina Dec 13 '16 at 02:22

0 Answers0