1,000 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
3
answers
336
views
How to check at compile-time if a = b (where a and b are arguments of type T&) is valid inside a template function?
I'm experimenting with a function template that performs assignment:
#include <vector>
#include <memory>
template<typename T>
void foo(T& a, const T& b) {
a = b;
}
int ...
1
vote
2
answers
99
views
Transforming a UTF-8 string in a const context
I have a function capable of translating UTF-8 characters into a custom 8-bit encoding:
const fn char_to_custom_encoding(c: char) -> u8;
I'd like to apply it at compile time to a string literal so ...
0
votes
1
answer
141
views
How can this Nim function deal with the special case at compile time?
I'm not a Nim user, but I was astonished by how the solution for this exercise on Exercism.
The text of the exercise is as follows:
Your task is to convert a number into its corresponding raindrop ...
-1
votes
2
answers
107
views
Is there a way to "configure" formatting at compile time? [duplicate]
I have struct/class that formats numbers. I want to tune its formatting parameters how i like. And this means I "need"(could be not, if there's another much more clever way of doing it?):
&...
3
votes
1
answer
101
views
What does "single run-time representation" mean in Bjarne Stroustrup's description of type erasure in "The C++ Programming Language"?
In The C++ Programming Language - 4th edition, in §25.3 at page 731-732 Bjarne Stroustrup shows a possible implementation of a Vector template class that's been specialized for all T* template ...
3
votes
1
answer
345
views
How can I iterate over struct fields at compile time in Zig to generate a serializer?
I'm learning Zig and I'm trying to write a generic function that automatically serializes any struct into JSON. In languages like Rust or Go, there are libraries that can iterate over the fields of a ...
2
votes
3
answers
236
views
C++: How to iterate over tuple in compile-time?
How to iterate over tuple in compile-time?
problem code:
#include <array>
#include <cstddef>
#include <tuple>
namespace {
class Solution {
public:
template <size_t ...
0
votes
1
answer
93
views
Compile‐time conversion of a JSON literal into a JsonString<char...> type in C++20 – overall design patterns? [closed]
I’m exploring ways in C++20 to represent a JSON text literal entirely in the type system, so that I can then write a metafunction like
template<typename Json, char... Key> struct HasKey;
...
0
votes
2
answers
94
views
DB2 LUW - Get Compile-time Failing Line Number in Stored Procedure
I've compiled other stored procedures (from SQuirrel© v4.8) and was able to figure out the error messages sufficiently to find my errors until I get a successful compile. But this time I'm getting ...
0
votes
0
answers
65
views
Can a function accepting Data.Vector.Fixed.Vector return Data.Vector.Fixed.Boxed.Vec2 or Vec3 based on the length of the input?
This is a bit of a follow up to a previous question.
Here's two functions that take 2 or 3 inputs respectively, and produce each a list of fixed-size vectors, of sizes 2 and 3 respectively:
import ...
0
votes
2
answers
194
views
Can I create a new string at compile time and use at runtime?
I am writing a log function that takes a format string and a variable number of arguments and captures std::source_location. This is not straightforward, so I tried the FormatWithLocation solution ...
0
votes
1
answer
135
views
Need help to understand how std::format can check its format string at compile-time
Out of curiosity, and with hope of learning useful compile-time techniques, I'm trying to understand how std::format performs compile-time checking of its arguments.
I started from the implementation ...
4
votes
4
answers
283
views
Check at compile time that a function call triggers a `static_assert(false)`
I have a template function with several type parameters and depending on those types, the function "calls" an static_assert(false). I want to know when my code fails to compile for specific ...
2
votes
1
answer
120
views
Filtering macro/array data at compile time in C
Is there a way to filter macro or array data at compile time in C?
For example:
#define THRESHOLD 5
#define MACRO_DATA \
X( 1 ) \
X( 8 ) \
X( 3 ) \
X( 12 ) \
X( 5 )
// ...
4
votes
1
answer
146
views
product enum class in c++
Is there a way to automatically (and at compile time) define a "product enum class" (i.e. an enum class that takes on values in the product space between two given enum classes)?
So if I ...