FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppgraphqlgen/samples/learn/HeroData.cpp at main · wravery/cppgraphqlgen · GitHub
wravery
cppgraphqlgen
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppgraphqlgen
/
samples
/
learn
/
HeroData.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (42 loc) · 1.3 KB
Breadcrumbs
cppgraphqlgen
/
samples
/
learn
/
HeroData.cpp
Copy path
File metadata and controls
51 lines (42 loc) · 1.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
Copyright (c) Microsoft Corporation. All rights reserved.
//
Licensed under the MIT License.
#
include
"
HeroData.h
"
#
include
"
DroidData.h
"
#
include
"
HumanData.h
"
#
include
"
CharacterObject.h
"
namespace
graphql
::learn {
std::shared_ptr<object::Character>
make_hero
(
const
SharedHero& hero)
noexcept
{
return
std::visit
(
[](
const
auto
& hero)
noexcept
{
using
hero_t
= std::
decay_t
<
decltype
(hero)>;
if
constexpr
(std::is_same_v<std::shared_ptr<Human>,
hero_t
>)
{
return
std::make_shared<object::Character>(std::make_shared<object::Human>(hero));
}
else
if
constexpr
(std::is_same_v<std::shared_ptr<Droid>,
hero_t
>)
{
return
std::make_shared<object::Character>(std::make_shared<object::Droid>(hero));
}
},
hero);
}
std::shared_ptr<object::Character>
make_hero
(
const
WeakHero& hero)
noexcept
{
return
std::visit
(
[](
const
auto
& hero)
noexcept
{
using
hero_t
= std::
decay_t
<
decltype
(hero)>;
if
constexpr
(std::is_same_v<std::weak_ptr<Human>,
hero_t
>)
{
return
std::make_shared<object::Character>(
std::make_shared<object::Human>(hero.
lock
()));
}
else
if
constexpr
(std::is_same_v<std::weak_ptr<Droid>,
hero_t
>)
{
return
std::make_shared<object::Character>(
std::make_shared<object::Droid>(hero.
lock
()));
}
},
hero);
}
}
//
namespace graphql::learn
Back
|
FazBrowse Home
|
New Git URL