Partial member function template specialisation and data member access

后端 未结 3 578
长情又很酷
长情又很酷 2021-01-13 16:22

I have a question regarding partial specialisation of templated member functions.

Background: The goal is to compute descriptive statistics of larg

3条回答
  •  Happy的楠姐
    2021-01-13 16:35

    Personally I'd be likely to choose your option 4, after all the only part of the iterator version that actually varies with type is the logic in the "single value version"

    However another option is to write your iterator versions to receive the mean and size by reference, mean and size can then be updated without them having to be made public.

    This will also help with testing as it allows push_impl to be tested separately (although with this approach you might consider that's no longer the best name for the function)

    As an aside, it would be better for your push_impl to be templated only on iterator type, you can deduce the value type inside push_impl in the same way that you currently so in your calling example, but with only the iterator type as a parameter there's no chance of accidently calling it with the wrong value type (which might not always cause a compilation error if the value type can be converted to the type you pass as "T")

提交回复
热议问题