Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
szorg5
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
torin
szorg5
Commits
a7e376af
Commit
a7e376af
authored
10 years ago
by
Tüske
Browse files
Options
Downloads
Patches
Plain Diff
PHP list() II. – a nehezebbik fele
parent
10a6fe9a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.cpp
+54
-26
54 additions, 26 deletions
main.cpp
szorg5.cdp
+1
-0
1 addition, 0 deletions
szorg5.cdp
with
55 additions
and
26 deletions
main.cpp
+
54
−
26
View file @
a7e376af
#include
<iostream>
#include
<string>
#include
<sstream>
#include
<vector>
#include
<tuple>
template
<
class
T
>
void
unpack
(
std
::
istringstream
&
s
,
T
&
arg
)
template
<
class
...
T
>
class
container
;
template
<
class
...
T
>
container
<
T
...
>
list
(
T
&
...
args
);
template
<
class
...
T
>
class
container
{
s
>>
arg
;
private:
std
::
tuple
<
T
&
...
>
tu
;
public:
container
(
T
&
...
args
)
:
tu
{
args
...}{}
template
<
class
...
F
>
friend
container
<
T
...
>
list
(
T
&
...
args
);
template
<
int
I
>
typename
std
::
enable_if
<
I
==
1
>::
type
readhelper
(
std
::
vector
<
std
::
string
>&
s
)
{
std
::
istringstream
is
{
s
[
I
-
1
]};
is
>>
std
::
get
<
I
-
1
>
(
tu
);
}
template
<
class
T
>
void
unpack
(
std
::
istringstream
&&
s
,
T
&
arg
)
template
<
int
I
>
typename
std
::
enable_if
<
I
!=
1
>::
type
readhelper
(
std
::
vector
<
std
::
string
>&
s
)
{
s
>>
arg
;
readhelper
<
I
-
1
>
(
s
);
std
::
istringstream
is
{
s
[
I
-
1
]};
is
>>
std
::
get
<
I
-
1
>
(
tu
);
}
template
<
class
T
,
class
...
V
>
void
unpack
(
std
::
i
string
stream
&
s
,
T
&
arg
,
V
&
...
arg
s
)
public
:
void
operator
=
(
std
::
vector
<
std
::
string
>&&
s
)
{
s
>>
arg
;
unpack
(
s
,
args
...);
readhelper
<
std
::
tuple_size
<
decltype
(
tu
)
>::
value
>
(
s
);
}
};
template
<
class
T
,
class
...
V
>
void
unpack
(
std
::
istringstream
&&
s
,
T
&
arg
,
V
&
...
args
)
template
<
class
...
T
>
container
<
T
...
>
list
(
T
&
...
args
)
{
s
>>
arg
;
unpack
(
s
,
args
...);
return
container
<
T
...
>
{
args
...};
}
template
<
class
...
T
>
void
unpack
(
std
::
string
s
,
T
&
...
args
)
std
::
vector
<
std
::
string
>
explode
(
std
::
string
s
)
{
unpack
(
std
::
istringstream
{
s
},
args
...);
std
::
vector
<
std
::
string
>
vec
;
std
::
istringstream
d
{
s
};
while
(
d
)
{
std
::
string
st
;
d
>>
st
;
vec
.
push_back
(
st
);
}
return
std
::
move
(
vec
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
a
;
double
b
;
std
::
string
c
;
unpack
(
"3 4.5 bla"
,
a
,
b
,
c
);
// a = 3; b = 4.5;
std
::
cout
<<
a
<<
":"
<<
b
<<
":"
<<
c
;
int
a
=
0
;
double
b
=
0
;
list
(
a
,
b
)
=
explode
(
"3 4.5"
);
std
::
cout
<<
a
<<
":"
<<
b
;
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
szorg5.cdp
0 → 100644
+
1
−
0
View file @
a7e376af
{"compileCppOptions":["-std\u003dc++11"],"requirements":[]}
\ No newline at end of file
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