This repository was archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_text.cpp
More file actions
44 lines (38 loc) · 1.45 KB
/
draw_text.cpp
File metadata and controls
44 lines (38 loc) · 1.45 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
// cpp-flexargs
//
// Copyright iorate 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Reference: http://www.kmonos.net/alang/boost/classes/parameter.html
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include "../flexargs.hpp"
using namespace std::literals;
using namespace flexargs;
namespace keywords {
inline constexpr keyword<struct x_> x;
inline constexpr keyword<struct y_> y;
inline constexpr keyword<struct msg_> msg;
inline constexpr keyword<struct width_> width;
}
template <class ...Args> // In Python:
void draw_text(Args &&...args) { // def draw_text(x: int, y: int, msg: Any, *, width: int = 4) -> None:
auto [x, y, msg, width] = match(
parameter<int>(keywords::x),
parameter<int>(keywords::y),
parameter(keywords::msg),
keyword_parameter<int>(keywords::width) = 4,
std::forward<Args>(args)...
);
std::cout << "(" << std::setw(width) << x << "," << std::setw(width) << y << ") : " << msg << std::endl;
}
int main() {
using namespace keywords;
auto www = "World"s;
draw_text(x = 1, y = 2, msg = "Hello"); // Specify parameters by keywords.
draw_text(msg = www, x = 3, y = 4, width = 8);
draw_text(5, 6, "GoodBye", width = 2); // You can also specify parameters by positions.
}