summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/metaprogramming.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:22 +0000
commitc21c3b0befeb46a51b6bf3758ffa30813bea0ff0 (patch)
tree9754ff1ca740f6346cf8483ec915d4054bc5da2d /ml/dlib/dlib/metaprogramming.h
parentAdding upstream version 1.43.2. (diff)
downloadnetdata-upstream/1.44.3.tar.xz
netdata-upstream/1.44.3.zip
Adding upstream version 1.44.3.upstream/1.44.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--ml/dlib/dlib/metaprogramming.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/ml/dlib/dlib/metaprogramming.h b/ml/dlib/dlib/metaprogramming.h
new file mode 100644
index 000000000..bc63041ff
--- /dev/null
+++ b/ml/dlib/dlib/metaprogramming.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2017 Davis E. King (davis@dlib.net)
+// License: Boost Software License See LICENSE.txt for the full license.
+#ifndef DLIB_METApROGRAMMING_Hh_
+#define DLIB_METApROGRAMMING_Hh_
+
+
+namespace dlib
+{
+
+// ----------------------------------------------------------------------------------------
+
+ template <size_t... n>
+ struct compile_time_integer_list
+ {
+ /*!
+ WHAT THIS OBJECT REPRESENTS
+ The point of this type is to, as the name suggests, hold a compile time list of integers.
+ As an example, here is something simple you could do with it:
+
+ template <size_t... ints>
+ void print_compile_time_ints (
+ compile_time_integer_list<ints...>
+ )
+ {
+ print(ints...);
+ }
+
+ int main()
+ {
+ print_compile_time_ints(compile_time_integer_list<0,4,9>());
+ }
+
+ Which just calls: print(0,4,9);
+
+ This is a simple example, but this kind of thing is useful in larger and
+ more complex template metaprogramming constructs.
+ !*/
+
+ template <size_t m>
+ struct push_back
+ {
+ typedef compile_time_integer_list<n..., m> type;
+ };
+ };
+
+// ----------------------------------------------------------------------------------------
+
+ template <size_t max>
+ struct make_compile_time_integer_range
+ {
+ /*!
+ WHAT THIS OBJECT REPRESENTS
+ This object makes a compile_time_integer_list containing the integers in the range [1,max] inclusive.
+ For example:
+ make_compile_time_integer_range<4>::type
+ evaluates to:
+ compile_time_integer_list<1,2,3,4>
+ !*/
+
+ typedef typename make_compile_time_integer_range<max-1>::type::template push_back<max>::type type;
+ };
+ // base case
+ template <> struct make_compile_time_integer_range<0> { typedef compile_time_integer_list<> type; };
+
+// ----------------------------------------------------------------------------------------
+
+}
+
+#endif // DLIB_METApROGRAMMING_Hh_
+
+