From 2dfaba6e32ef027036378e499d9cb28aa2e6220f Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Wed, 4 Dec 2019 15:42:56 -0500 Subject: DRTVWR-494: Add llmake_heap(); update to variadic llmake(). --- indra/llcommon/llmake.h | 52 ++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'indra/llcommon/llmake.h') diff --git a/indra/llcommon/llmake.h b/indra/llcommon/llmake.h index 08744f90fb..02463d97ea 100644 --- a/indra/llcommon/llmake.h +++ b/indra/llcommon/llmake.h @@ -12,10 +12,8 @@ * * also relevant: * - * Template argument deduction for class templates - * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0091r3.html - * was apparently adopted in June 2016? Unclear when compilers will - * portably support this, but there is hope. + * Template argument deduction for class templates (C++17) + * https://en.cppreference.com/w/cpp/language/class_template_argument_deduction * * $LicenseInfo:firstyear=2015&license=viewerlgpl$ * Copyright (c) 2015, Linden Research, Inc. @@ -25,37 +23,43 @@ #if ! defined(LL_LLMAKE_H) #define LL_LLMAKE_H -/*==========================================================================*| -// When we allow ourselves to compile with C++11 features enabled, this form -// should generically handle an arbitrary number of arguments. - +/** + * Usage: llmake(args...) + * + * Deduces the types T... of 'args' and returns an instance of + * SomeTemplate(args...). + */ template class CLASS_TEMPLATE, typename... ARGS> CLASS_TEMPLATE llmake(ARGS && ... args) { return CLASS_TEMPLATE(std::forward(args)...); } -|*==========================================================================*/ -// As of 2015-12-18, this is what we'll use instead. Add explicit overloads -// for different numbers of template parameters as use cases arise. +/// dumb pointer template just in case that's what's wanted +template +using dumb_pointer = T*; /** - * Usage: llmake(arg) + * Same as llmake(), but returns a pointer to a new heap instance of + * SomeTemplate(args...) using the pointer of your choice. * - * Deduces the type T of 'arg' and returns an instance of SomeTemplate - * initialized with 'arg'. Assumes a constructor accepting T (by value, - * reference or whatever). + * @code + * auto* dumb = llmake_heap(args...); + * auto shared = llmake_heap(args...); + * auto unique = llmake_heap(args...); + * @endcode */ -template class CLASS_TEMPLATE, typename ARG1> -CLASS_TEMPLATE llmake(const ARG1& arg1) -{ - return CLASS_TEMPLATE(arg1); -} - -template class CLASS_TEMPLATE, typename ARG1, typename ARG2> -CLASS_TEMPLATE llmake(const ARG1& arg1, const ARG2& arg2) +// POINTER_TEMPLATE is characterized as template rather than as +// template because (e.g.) std::unique_ptr has multiple template +// arguments. Even though we only engage one, std::unique_ptr doesn't match a +// template template parameter that itself takes only one template parameter. +template class CLASS_TEMPLATE, + template class POINTER_TEMPLATE=dumb_pointer, + typename... ARGS> +POINTER_TEMPLATE> llmake_heap(ARGS&&... args) { - return CLASS_TEMPLATE(arg1, arg2); + return POINTER_TEMPLATE>( + new CLASS_TEMPLATE(std::forward(args)...)); } #endif /* ! defined(LL_LLMAKE_H) */ -- cgit v1.2.3 From 69fbe647abe3942ced02f14f0adc477630d9dd7e Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 9 Dec 2019 11:33:08 -0500 Subject: DRTVWR-494: VS 2013 can't yet handle variadic llmake(). --- indra/llcommon/llmake.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'indra/llcommon/llmake.h') diff --git a/indra/llcommon/llmake.h b/indra/llcommon/llmake.h index 02463d97ea..f901ee2bf1 100644 --- a/indra/llcommon/llmake.h +++ b/indra/llcommon/llmake.h @@ -23,6 +23,9 @@ #if ! defined(LL_LLMAKE_H) #define LL_LLMAKE_H +// If we're using a compiler newer than VS 2013, use variadic llmake(). +#if (! defined(_MSC_VER)) || (_MSC_VER > 1800) + /** * Usage: llmake(args...) * @@ -35,6 +38,22 @@ CLASS_TEMPLATE llmake(ARGS && ... args) return CLASS_TEMPLATE(std::forward(args)...); } +#else // older implementation for VS 2013 + +template class CLASS_TEMPLATE, typename ARG1> +CLASS_TEMPLATE llmake(const ARG1& arg1) +{ + return CLASS_TEMPLATE(arg1); +} + +template class CLASS_TEMPLATE, typename ARG1, typename ARG2> +CLASS_TEMPLATE llmake(const ARG1& arg1, const ARG2& arg2) +{ + return CLASS_TEMPLATE(arg1, arg2); +} + +#endif // VS 2013 workaround + /// dumb pointer template just in case that's what's wanted template using dumb_pointer = T*; -- cgit v1.2.3 From ce2b56b2f899542b5d7df3e118cbae1fdd7df722 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 14 Oct 2019 15:43:06 -0400 Subject: DRTVWR-476: Engage variadic llmake() implementation. --- indra/llcommon/llmake.h | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'indra/llcommon/llmake.h') diff --git a/indra/llcommon/llmake.h b/indra/llcommon/llmake.h index f901ee2bf1..02463d97ea 100644 --- a/indra/llcommon/llmake.h +++ b/indra/llcommon/llmake.h @@ -23,9 +23,6 @@ #if ! defined(LL_LLMAKE_H) #define LL_LLMAKE_H -// If we're using a compiler newer than VS 2013, use variadic llmake(). -#if (! defined(_MSC_VER)) || (_MSC_VER > 1800) - /** * Usage: llmake(args...) * @@ -38,22 +35,6 @@ CLASS_TEMPLATE llmake(ARGS && ... args) return CLASS_TEMPLATE(std::forward(args)...); } -#else // older implementation for VS 2013 - -template class CLASS_TEMPLATE, typename ARG1> -CLASS_TEMPLATE llmake(const ARG1& arg1) -{ - return CLASS_TEMPLATE(arg1); -} - -template class CLASS_TEMPLATE, typename ARG1, typename ARG2> -CLASS_TEMPLATE llmake(const ARG1& arg1, const ARG2& arg2) -{ - return CLASS_TEMPLATE(arg1, arg2); -} - -#endif // VS 2013 workaround - /// dumb pointer template just in case that's what's wanted template using dumb_pointer = T*; -- cgit v1.2.3