Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
fab81527
Commit
fab81527
authored
May 20, 2016
by
Harris Hancock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reimplement FromAny_ using VoidSfinae
parent
057946f0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
9 deletions
+33
-9
common.h
c++/src/capnp/common.h
+33
-9
No files found.
c++/src/capnp/common.h
View file @
fab81527
...
...
@@ -250,18 +250,42 @@ template <typename T>
using
FromServer
=
typename
kj
::
Decay
<
T
>::
Serves
;
// FromBuilder<MyType::Server> = MyType (for any Cap'n Proto interface type).
struct
FromAny_
{
template
<
typename
T
,
typename
X
=
FromReader
<
T
>>
static
X
apply
(
T
*
,
int
);
template
<
typename
T
,
typename
X
=
FromBuilder
<
T
>>
static
X
apply
(
T
*
,
char
);
template
<
typename
T
,
typename
X
=
FromPipeline
<
T
>>
static
X
apply
(
T
*
,
long
);
// note that ::Client is covered by FromReader
template
<
typename
T
,
typename
X
=
FromServer
<
T
>>
static
X
apply
(
kj
::
Own
<
T
>*
,
short
);
template
<
typename
T
,
typename
=
kj
::
EnableIf
<
style
<
T
>
()
==
Style
::
PRIMITIVE
>>
static
T
apply
(
T
*
,
unsigned
int
);
template
<
typename
T
,
typename
=
void
>
struct
FromAny_
;
template
<
typename
T
>
struct
FromAny_
<
T
,
kj
::
VoidSfinae
<
FromReader
<
T
>>>
{
using
Type
=
FromReader
<
T
>
;
};
template
<
typename
T
>
struct
FromAny_
<
T
,
kj
::
VoidSfinae
<
FromBuilder
<
T
>>>
{
using
Type
=
FromBuilder
<
T
>
;
};
template
<
typename
T
>
struct
FromAny_
<
T
,
kj
::
VoidSfinae
<
FromPipeline
<
T
>>>
{
using
Type
=
FromPipeline
<
T
>
;
};
// Note that T::Client is covered by FromReader
template
<
typename
T
>
struct
FromAny_
<
kj
::
Own
<
T
>
,
kj
::
VoidSfinae
<
FromServer
<
T
>>>
{
using
Type
=
FromServer
<
T
>
;
};
template
<
typename
T
>
struct
FromAny_
<
T
,
kj
::
EnableIf
<
_
::
Kind_
<
T
>::
kind
==
Kind
::
PRIMITIVE
||
_
::
Kind_
<
T
>::
kind
==
Kind
::
ENUM
>>
{
// TODO(msvc): Ideally the EnableIf condition would be `style<T>() == Style::PRIMITIVE`, but MSVC
// cannot yet use style<T>() in this constexpr context.
using
Type
=
kj
::
Decay
<
T
>
;
};
template
<
typename
T
>
using
FromAny
=
kj
::
Decay
<
decltype
(
FromAny_
::
apply
(
kj
::
instance
<
T
*>
(),
0
))
>
;
using
FromAny
=
typename
FromAny_
<
T
>::
Type
;
// Given any Cap'n Proto value type as an input, return the Cap'n Proto base type. That is:
//
// Foo::Reader -> Foo
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment