--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/66dcaca8-65d4-4575-8d6a-764c8d45279b%40isocpp.org.
On Mon, Feb 20, 2017 at 2:31 PM, Curious <aa...@umich.edu> wrote:I have seen some problems in the past associated with passing objects of classes that are instantiations of templates with multiple parameter with one or more than one default parameters. For example, if I have the following functionvoid func(const std::vector<int>& vec) { ... }I cannot call it like soauto vec = std::vector<int, MyAllocator>{};func(vec);Because the type of the second parameter (i.e. the allocator) is different. Maybe the following type trait can be useful for situations like this?template <typename Type, template <typename...> class InstantiationType>struct is_instantiation_of : std::integral_constant<bool, false> {};template <template <typename...> class Thing, typename... Args>struct is_instantiation_of<Thing<Args...>, Thing> : std::integral_constant<bool, true> {};This way one could write a function that accepts any type of vector like this (without concepts)template <typename Type, template <typename...> class Thing>using EnableIfIsInstantiationOf = std::enable_if_t<is_instantiation_of<Type, Thing>::value>;template <typename Vector, EnableIfIsInstantiationOf<Vector, std::vector>* = nullptr>void func(const Vector& vec) { ... }void func(const std::vector<T, Alloc>& vec) { ... }Sorry maybe I'm missing something but why can't you just do this?template <class T, class Alloc>
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/66dcaca8-65d4-4575-8d6a-764c8d45279b%40isocpp.org.
--Brian Bi
-Richard
I feel like it would be a much more readable alternative than that because the solution of including the template parameters becomes a lot more complicated when there are multiple arguments, and each have two-three "hidden" template parameters.Also I feel like it would help people write good specialized functions, since there are a lot of functions that can be written to accept types with different interfaces but do the same logical thing, for example, you can think of a binary search function that would linearly iterate if a linked list would be passed and randomly jump around when a vector is passed.
Well you can't really binary search a linked list can you? If you do try and do that, it would degrade to worse than linear time.
Also when someone says binary search a range I think its safe to assume that the range is already sorted."When is not something you can determine from its type." -- It's not something you should be determining at runtime either, no binary search function should start by inspecting the range to see if it's already sorted.
On Tuesday, February 21, 2017 at 12:26:37 AM UTC-5, Curious wrote:Well you can't really binary search a linked list can you? If you do try and do that, it would degrade to worse than linear time.
Right. Which is why `std::binary_search` and `std::equal_range` require random access iterators.