summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-06-17 14:06:23 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-06-17 14:06:23 +0100
commit0b887cd08315967d38a45ce4ec70e5bb3eb84752 (patch)
treebaef300ec8edfa87f00fd5aacc0bfd2aa069a8f6
parentMassively simplified CTF with C++17 constexpr (diff)
downloadlibadhocutil-0b887cd08315967d38a45ce4ec70e5bb3eb84752.tar.bz2
libadhocutil-0b887cd08315967d38a45ce4ec70e5bb3eb84752.tar.xz
libadhocutil-0b887cd08315967d38a45ce4ec70e5bb3eb84752.zip
Use template auto types throughout CTF
-rw-r--r--libadhocutil/compileTimeFormatter.h24
1 files changed, 12 insertions, 12 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h
index 4b268f7..82cfa79 100644
--- a/libadhocutil/compileTimeFormatter.h
+++ b/libadhocutil/compileTimeFormatter.h
@@ -17,7 +17,7 @@ namespace AdHoc {
}
template<const auto & S, auto n, auto start = 0, auto L = strlen<S>()>
- static constexpr int strchr()
+ static constexpr auto strchr()
{
static_assert(start <= L);
decltype(start) off = start;
@@ -34,13 +34,13 @@ namespace AdHoc {
return off;
}
- template <const char * const &, auto> class Formatter;
+ template <const auto &, auto> class Formatter;
- template<const char * const & S, auto L, auto pos, typename stream, char ...>
+ template<const auto & S, auto L, auto pos, typename stream, auto ...>
struct StreamWriter {
};
- template<const char * const & S, auto L, auto pos, typename stream>
+ template<const auto & S, auto L, auto pos, typename stream>
struct StreamWriterBase {
template<typename ... Pn>
static inline void next(stream & s, const Pn & ... pn)
@@ -50,12 +50,12 @@ namespace AdHoc {
};
#define StreamWriterT(C...) \
- template<const char * const & S, auto L, auto pos, typename stream, char ... sn> \
+ template<const auto & S, auto L, auto pos, typename stream, auto ... sn> \
struct StreamWriter<S, L, pos, stream, '%', C, sn...> : \
public StreamWriterBase<S, L, BOOST_PP_VARIADIC_SIZE(C) + pos, stream>
#define StreamWriterTP(P, C...) \
- template<const char * const & S, auto L, auto pos, typename stream, char P, char ... sn> \
+ template<const auto & S, auto L, auto pos, typename stream, auto P, auto ... sn> \
struct StreamWriter<S, L, pos, stream, '%', C, sn...> : \
public StreamWriterBase<S, L, BOOST_PP_VARIADIC_SIZE(C) + pos, stream>
@@ -80,7 +80,7 @@ namespace AdHoc {
};
// Unknown stream writer formatter
- template<const char * const & S, auto L, auto pos, typename stream, char ... sn>
+ template<const auto & S, auto L, auto pos, typename stream, auto ... sn>
struct StreamWriter<S, L, pos, stream, '%', sn...> {
template<typename ... Pn>
static void write(stream &, const Pn & ...)
@@ -94,10 +94,10 @@ namespace AdHoc {
* Compile time string formatter.
* @param S the format string.
*/
- template <const char * const & S, auto L = strlen<S>()>
+ template <const auto & S, auto L = strlen<S>()>
class Formatter {
private:
- template<const char * const &, auto, auto, typename> friend struct StreamWriterBase;
+ template<const auto &, auto, auto, typename> friend struct StreamWriterBase;
public:
/**
@@ -125,13 +125,13 @@ namespace AdHoc {
}
private:
- template<typename stream, int pos, typename ... Pn>
+ template<typename stream, auto pos, typename ... Pn>
struct Parser {
static inline stream &
run(stream & s, const Pn & ... pn)
{
if (pos != L) {
- constexpr int ph = strchrnul<S, '%', pos>();
+ constexpr auto ph = strchrnul<S, '%', pos>();
if constexpr (ph != pos) {
s.write((S + pos), ph - pos);
}
@@ -141,7 +141,7 @@ namespace AdHoc {
}
return s;
}
- template<int ph, int off = 0, char ... Pck>
+ template<auto ph, auto off = 0, auto ... Pck>
static inline void packAndWrite(stream & s, const Pn & ... pn)
{
if constexpr (ph + off == L || sizeof...(Pck) == 32) {