-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionArguments.cpp
More file actions
57 lines (46 loc) · 1.24 KB
/
FunctionArguments.cpp
File metadata and controls
57 lines (46 loc) · 1.24 KB
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
52
53
54
55
56
57
#include "FunctionArguments.h"
FunctionArguments::FunctionArguments(std::vector<std::string>&& _names)
{
names = std::move(_names);
for (size_t i = 0; i < names.size(); ++i)
if (names[i] == "...")
{
if (is_template())
throw std::exception("2 or more templates in function");
pos = i;
}
}
bool FunctionArguments::can_call(size_t sz) const
{
if (is_template())
return size() >= sz;
return size() == sz;
}
std::pair<values, std::vector<type>>
FunctionArguments::superimpose(std::vector<type>&& args) const
{
values vals;
std::vector<type> templates;
if (!is_template()) //always valid
{
if (names.size() != args.size()) //doesn't need but i want
throw std::exception("Arguments size didn't match");
for (size_t i = 0; i < names.size(); ++i)
vals[names[i]] = args[i];
}
else
{
if (args.size() < size())
throw std::exception("Not enough arguments");
for (size_t i = 0; i < pos; ++i)
vals[names[i]] = args[i];
//args.size() - 1 = t + names.size() - 1
int64_t t = args.size() - names.size();
for (size_t i = names.size() - 1; i > pos; --i)
vals[names[i]] = args[t + i];
size_t last = t + pos;
for (size_t i = pos; i <= last; ++i)
templates.push_back(args[i]);
}
return { vals, templates };
}