Questions tagged [compile-time]
Refers to the information that can be inferred or known at the time source code is compiled, as opposed to information that can only be inferred when source code is run. Do not use this tag for questions about the time it takes for source code to be compiled.
compile-time
964
questions
0
votes
1
answer
53
views
Accessing comptime array in runtime with for loop
I need to be able to loop through a comptime array in runtime, but since the indexes of the for-loop is calculated at runtime, I can't do that. Is there a way to do this?
const std = @import("std&...
0
votes
1
answer
89
views
How can I handle a string generated from macro within procedural macro?
I use include_str!() to import the string from a file and pass it into a proc_marco, but it does not work. I get an expected string literal error. Here is my code:
macro_rules! ptcl_layer {
() =&...
0
votes
2
answers
57
views
Is CallerMemberNameAttribute guaranteed to be evaluated before inlining?
Here is the documentation for the attribute. It does not mention when it is evaluated.
Here is the documentation for the greater 'CallerInformation' mechanism. It makes the following assertion:
...
3
votes
1
answer
64
views
Is there a way to constraint a type parameter to accept only types that are specific (rejects abstract type parameters)?
The following code compiles with no warning but does not work as intended.
inline def isXAssignableToY[X <: Matchable, Y]: Boolean = {
inline erasedValue[X] match {
case _: Y => true
...
3
votes
1
answer
102
views
How to validate strings to compile time?
I am trying to make the following code work:
#include <string>
#include <tuple>
#include <print>
template<char Specifier>
struct ParseSpecifier;
template<>
struct ...
0
votes
2
answers
70
views
C++ Template Arguments Sort
I'm looking for template code to sort template arguments by the return value of their static member function static constexpr int getType(), something like:
#include <iostream>
#include <...
1
vote
2
answers
54
views
Sums over overlapping rectangular slices of a 2D array
I need to calculate multiple sums, each sum being over an axis oriented rectangular slice of a 2D array. Many of the slices will overlap, and therefore there will be many shared terms in the sums. To ...
0
votes
2
answers
108
views
Function overloading depending on compile-time object state
Consider having a simple class, that writes integers to cout depending on its state:
#include <iostream>
class NotAWriter{
public:
NotAWriter& operator<<(const int& arg) {
...
2
votes
1
answer
49
views
Is it possible to emit a dynamically generated compiler error message in inline methods or clauses?
Summoning an instance by means of a method context parameter allows to customize the error message declaratively annotating the parameter with @implicitNotFound which requires a literal string that ...
3
votes
3
answers
167
views
How to check if a macro argument is an integer literal in C
I'm trying to do a macro like this:
#define STRING(i) \
struct STRING##i \
{ \
size_t len; \
char chars[i]; \
}
but the problem is this works with constexpr arguments like this:
constexpr int ...
0
votes
0
answers
25
views
Why can I not get a compile-time error referencing a non-existent key in a Dart map?
I am new to Dart and was expecting to get a compile-time error for the following code:
final Map screens = const {
"START": 'start_screen',
"QUESTIONS": 'questions_screen'...
0
votes
1
answer
70
views
Placing data at an address given by a constant arithmetic expression [duplicate]
Context
My team upgraded our project from using Arm Compiler for Embedded 5 to Embedded 6. In our code, we place data at a specific location in RAM like so:
#define RAM_START_ADDR <some constant>...
0
votes
2
answers
95
views
Is there an effective way to assert an constexpr-if branch is executed?
int f(auto obj) {
if constexpr (HasFastGetData<decltype(obj)>) {
return obj.FastGetData();
} else {
return obj.GetData();
}
}
int main() {
B obj;
f(obj);
...
9
votes
2
answers
229
views
What is the storage duration and lifetime of a non type template parameter and how can it be used for compile-time computation?
In C++ Weekly - Ep 313 - The constexpr Problem That Took Me 5 Years To Fix!, Jason Turner demonstrates several compile-time techniques in order to construct a std::string at compile-time and then pass ...
0
votes
0
answers
28
views
How to Create constexpr Array Where Elements Depend on the Array’s Size? [duplicate]
How can I create a constexpr array, where the array elements are calculated and depend on the size of the array? Look at the example below in the initializer list to see what I mean.
template <...