Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
2dfaba6e
Commit
2dfaba6e
authored
5 years ago
by
Nat Goodspeed
Browse files
Options
Downloads
Patches
Plain Diff
DRTVWR-494: Add llmake_heap(); update to variadic llmake().
parent
1f7335fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indra/llcommon/llmake.h
+28
-24
28 additions, 24 deletions
indra/llcommon/llmake.h
with
28 additions
and
24 deletions
indra/llcommon/llmake.h
+
28
−
24
View file @
2dfaba6e
...
@@ -12,10 +12,8 @@
...
@@ -12,10 +12,8 @@
*
*
* also relevant:
* also relevant:
*
*
* Template argument deduction for class templates
* Template argument deduction for class templates (C++17)
* http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0091r3.html
* https://en.cppreference.com/w/cpp/language/class_template_argument_deduction
* was apparently adopted in June 2016? Unclear when compilers will
* portably support this, but there is hope.
*
*
* $LicenseInfo:firstyear=2015&license=viewerlgpl$
* $LicenseInfo:firstyear=2015&license=viewerlgpl$
* Copyright (c) 2015, Linden Research, Inc.
* Copyright (c) 2015, Linden Research, Inc.
...
@@ -25,37 +23,43 @@
...
@@ -25,37 +23,43 @@
#if ! defined(LL_LLMAKE_H)
#if ! defined(LL_LLMAKE_H)
#define LL_LLMAKE_H
#define LL_LLMAKE_H
/*==========================================================================*|
/**
// When we allow ourselves to compile with C++11 features enabled, this form
* Usage: llmake<SomeTemplate>(args...)
// should generically handle an arbitrary number of arguments.
*
* Deduces the types T... of 'args' and returns an instance of
* SomeTemplate<T...>(args...).
*/
template
<
template
<
typename
...
>
class
CLASS_TEMPLATE
,
typename
...
ARGS
>
template
<
template
<
typename
...
>
class
CLASS_TEMPLATE
,
typename
...
ARGS
>
CLASS_TEMPLATE
<
ARGS
...
>
llmake
(
ARGS
&&
...
args
)
CLASS_TEMPLATE
<
ARGS
...
>
llmake
(
ARGS
&&
...
args
)
{
{
return
CLASS_TEMPLATE
<
ARGS
...
>
(
std
::
forward
<
ARGS
>
(
args
)...);
return
CLASS_TEMPLATE
<
ARGS
...
>
(
std
::
forward
<
ARGS
>
(
args
)...);
}
}
|*==========================================================================*/
// As of 2015-12-18, this is what we'll use instead. Add explicit overloads
/// dumb pointer template just in case that's what's wanted
// for different numbers of template parameters as use cases arise.
template
<
typename
T
>
using
dumb_pointer
=
T
*
;
/**
/**
* Usage: llmake<SomeTemplate>(arg)
* Same as llmake(), but returns a pointer to a new heap instance of
* SomeTemplate<T...>(args...) using the pointer of your choice.
*
*
* Deduces the type T of 'arg' and returns an instance of SomeTemplate<T>
* @code
* initialized with 'arg'. Assumes a constructor accepting T (by value,
* auto* dumb = llmake_heap<SomeTemplate>(args...);
* reference or whatever).
* auto shared = llmake_heap<SomeTemplate, std::shared_ptr>(args...);
* auto unique = llmake_heap<SomeTemplate, std::unique_ptr>(args...);
* @endcode
*/
*/
template
<
template
<
typename
>
class
CLASS_TEMPLATE
,
typename
ARG1
>
// POINTER_TEMPLATE is characterized as template<typename...> rather than as
CLASS_TEMPLATE
<
ARG1
>
llmake
(
const
ARG1
&
arg1
)
// template<typename T> because (e.g.) std::unique_ptr has multiple template
{
// arguments. Even though we only engage one, std::unique_ptr doesn't match a
return
CLASS_TEMPLATE
<
ARG1
>
(
arg1
);
// template template parameter that itself takes only one template parameter.
}
template
<
template
<
typename
...
>
class
CLASS_TEMPLATE
,
template
<
typename
...
>
class
POINTER_TEMPLATE
=
dumb_pointer
,
template
<
template
<
typename
,
typename
>
class
CLASS_TEMPLATE
,
typename
ARG1
,
typename
ARG
2
>
typename
...
ARG
S
>
CLASS_TEMPLATE
<
ARG
1
,
ARG2
>
llmake
(
const
ARG1
&
arg1
,
const
ARG2
&
arg
2
)
POINTER_TEMPLATE
<
CLASS_TEMPLATE
<
ARG
S
...
>
>
llmake
_heap
(
ARGS
&&
...
arg
s
)
{
{
return
CLASS_TEMPLATE
<
ARG1
,
ARG2
>
(
arg1
,
arg2
);
return
POINTER_TEMPLATE
<
CLASS_TEMPLATE
<
ARGS
...
>>
(
new
CLASS_TEMPLATE
<
ARGS
...
>
(
std
::
forward
<
ARGS
>
(
args
)...));
}
}
#endif
/* ! defined(LL_LLMAKE_H) */
#endif
/* ! defined(LL_LLMAKE_H) */
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment