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.
868
questions
1
vote
1
answer
25
views
`Error: request to generate code for .compileTime proc`
I have a small helper proc that is supposed to tell me at compile-time whether a type is an object-type or not.
func isObject*[T](val: typedesc[T]): bool {.compileTime.} = T is (object or ref object) ...
0
votes
1
answer
55
views
Automatically declare member pointers to their own classes
My question is:
Is there a way to declare static member pointers to their own classes automatically?
I have a C++ state machine, in which classes have static pointers to their own classes. This means ...
1
vote
1
answer
31
views
Initializing correct union member based on compile time evaluation
I want to initialize different union member depending if a macro expression is a constant or a variable.
So far I've found GCC extension __builtin_constant_p() which evaluates an expression and ...
1
vote
1
answer
51
views
Is there any way to check, from a .hpp file, if C stdio functions are used in the corresponding .cpp file?
I have the following question. Supposing I have an header file header.hpp which is include in a test.cpp file. Is it possible to add instructions to the header.hpp file in order to check (maybe at ...
1
vote
1
answer
65
views
Rust generic parameters and compile time if
Using C++ template and if constexpr I found a trick that I like a lot: suppose you have a function with some tunable option that are known compile-time, I can write something like
template <bool ...
1
vote
1
answer
29
views
When does a variable get its value assigned in c#?
Example:
string input=Console.ReadLine();
Base obj1;
if (input=="a"){
obj1=Derived();
else{
obj1=Base();
}
In this case i know that a variable gets its value at runtime. But ...
1
vote
1
answer
54
views
Cast pointers in consteval
I wanted to make a compiletime data encryptor.
I tried this by creating a struct with a buffer, and a constructor for that struct that
would read an array of structures in that buffer. And because I ...
1
vote
0
answers
40
views
std::array unique constexpr [duplicate]
I want to remove duplicates from a constexpr std::array at compile time.
Basically, I'm trying to implement a consteval function, which returns a copy of the original array without duplicates:
...
1
vote
1
answer
162
views
Why Java compiler Not get the duplicate class error while defining an inner class inside a loop
As you know we can define an inner class inside a loop:
for (int i = 0; i < 2; i++) {
class InnerClass {
void aMethod() {
System.out.println("Inner Class Method");
...
0
votes
1
answer
35
views
Is a compile-time error generated as C# code is being written or when the program is being compiled?
Been looking for online sources (especially MS documentations) that clearly say when a compile-time error is generated. Sadly I have not found any. I do know that a compile-time error is generated ...
3
votes
1
answer
64
views
Unable to recursively multiply BigInt beyond a certain number of iterations at compile-time in D
I need to get the product of an arbitrary number of variables. The actual number of variables and their values will be known at compile-time, however I cannot hardcode these because they come from ...
4
votes
2
answers
135
views
Why can't C (nor C++) optimize this recursive experiment?
I was thinking about functional programming techniques, recursions, and constness, and linked lists, so I made two experiments to test my compiler. In theory the compiler should be capable of ...
0
votes
2
answers
66
views
How do you generate a struct dynamically at compile time in Rust?
I have the following:
struct Health {
health: f32,
}
struct Position {
position: Vec2,
}
struct Collections {
healths: Vec<Health>,
positions: Vec<Position>,
}
I would like to ...
-1
votes
2
answers
69
views
Does the standard or some Boost library offer a compile-time variant?
I'm not asking how to Get type of a std::variant member at a given index during compile time.
I'm asking whether the standard or some boost library offer a std::variant-like class whose contained type ...
1
vote
1
answer
41
views
Create enum of generic variants of a type
I have a struct with a constant generic parameter VAR. This parameter is used in methods, improving the runtime speed, due to large amount of comparisons can be done compile time.
It's rather ...
-1
votes
1
answer
89
views
Is there a way to static_assert a variable reference given in a template parameter?
struct Config
{
int version = 1;
};
template<Config& config /* , ... */>
struct Peripheral
{
const Config config_ = config;
static_assert(config_.version > 1, "Config ...
0
votes
1
answer
32
views
fully qualified name vs import statement [duplicate]
case 1.
class A extends java.util.ArrayList
{
public static void main(String[] args)
{
ArrayList a=new ArrayList();
}
}
Here I am getting a compiletime error saying,
cannot ...
2
votes
2
answers
90
views
C++ Compile time index/tuple access for tensor
I have a compile time tensor class. Now i would like to implement index access like this:
std::array<std::array<std::array<int, 3>, 2>, 1> myTensor;
template <class... Indices>...
0
votes
1
answer
69
views
deferred selection of types during compile-time
Is there a standard way for me to select a type at compile-time in c++20 when the type depends on compile-time information available later in the function, i.e. the type is "deferred" ...
0
votes
0
answers
102
views
Can I reduce the compile-time of my header-only library with a separate translation unit?
I am looking for a way to reduce compile-time for header-only libraries. If there are only headers, each translation unit must compile all functions it needs, hence there is a lot of duplicate work ...
0
votes
0
answers
41
views
Increased compile time for interface generation and template instantiation in ros2
with this post i am referring to my own question on ros answers, hoping that the bigger stackoverflow community may help me with my issue (https://answers.ros.org/question/400257/increased-compile-...
0
votes
0
answers
129
views
How to optimize build times for unit test target
We have an 4 years old iOS app with partly old codebase. We are using the VIPER architecture, Quick and Nimble and want to use TDD (test driven development) for our new module (feature).
For TDD you ...
1
vote
2
answers
131
views
How to embed the data into array in compile time in C++?
I want to load a database into an array at compile time like:
//a.dat
1 2 3 4 5
int main(){
unsigned int a[5]=f("a.dat");
}
But I can't find a simple solution in StackOverflow. Is ...
1
vote
0
answers
143
views
Check template parameter pack for specific values
I am writing a small Tensor class, that should look like this:
using namespace std; // for simplicity
template<typename T, size_t N>
class Tensor {
size_t rank_;
array<int, N> ...
-1
votes
1
answer
87
views
How to enumerate a constant array at compile time in C++?
I am trying to generate a hash at COMPILE TIME from a literal string (array of characters). For example:
unsigned long long compiledHash = ComputeHash("literal string");
I am currently ...
1
vote
1
answer
45
views
encapsulate reference to templated function inside compile time object
As of writing this metaclasses are sadly not a feature.
I am trying to encapsulate a reference to a templated function inside some compile time object, ideally the compile time object is easy to make, ...
0
votes
0
answers
34
views
How to find the fastest algorithm inside a single script file?
I have many answers to a problem and I want to test which algorithm/answer is the best. Calculating big O notation complexity is very hard (have to do it by hand, with pen, and paper) so I decide to ...
0
votes
0
answers
11
views
How to stop workflow from calling dll function at compile time
I have a workflow xml that references a function in a separate DLL. When I compile (VS2019) the workflow XML, the reference to the Function in the Dll actually calls the function at compile time. The ...
0
votes
1
answer
76
views
How to implement zero-overhead Inversion of Control
Almost every OOP programmer has been exposed to the concept of Inversion of control. In C++, we can implement that principle with dynamic callbacks (i.e. functors such as lambdas and function pointers)...
-3
votes
1
answer
76
views
How to Cut Down Execution Time?
Here is a code snippet of a function that takes vector of strings (vector of customer names) and need to find names which occurs with some frequency. How to make it run faster (faster than 2 seconds ...
1
vote
1
answer
60
views
Deduce complete type of parent from one of its template parameters
I want to get the typename of the parent that has a specific template parameter(key).
For example, if I have a parent MyParent<int, 1>, I want to be able to get that type(MyParent<int, 1>) ...
1
vote
0
answers
69
views
Including only Eigen small matrices?
I do a lot of computational geometry, and so I often use eigen for the bigger/fancier linear algebra operations. This means that I don;t use things like glm, because it would make me spend a lot of ...
0
votes
0
answers
92
views
Prevent logging personally-identify or sensitive data with generic type that excludes sensitive properties
I want to enhance my logger with a compile-time safety check that prevents me from logging personally-identifying or sensitive data. Here's what I imagine the interface could look like:
logger.LogInfo(...
0
votes
1
answer
36
views
Ways of defining accepted template parameter values
My program has a series of functions that take a template argument for an integer that needs to be known at compile time. The functions only accept a few possible values for this integer, and I am ...
8
votes
1
answer
96
views
What's the difference between $?CLASS and ::?CLASS
The Raku docs describe ::?CLASS as a compile-time variable that answers "Which class am I in?". Then, a couple of paragraphs later, it mentions $?CLASS, and says that it answers "Which ...
3
votes
1
answer
838
views
fmt Library - Formatting to a (compile-time) string_view
I would like to use the fmt library to create a string_view from my format args. There is plenty documented about passing in a compile-time string as the format string, however, I want to output a ...
0
votes
0
answers
30
views
Checking type resolution compltetly at runtime
I'm writing some tests that checks that library I'm contributing to is working in intended way. For example I want to check if correct types get inferred for right expressions and so on.
For example ...
2
votes
0
answers
399
views
How to set Swift flags for local packages in Xcode?
I'm trying to figure out how long does the Swift compiler take to build my app every time and reduce time on type checks and functions where possible. I found many articles on the internet, explaining ...
0
votes
1
answer
133
views
Is possible create QString at compile time?
Consider below code:
static constexpr QString FOO = QStringLiteral("foo");
but can not compile this line because QString has not default destructor.
How I can do something like this?
1
vote
2
answers
104
views
Compile-time ceiling function, for literals, in C?
I have a C program which involves some floating-point literal that's defined by a macro. And - it just so happens that in a performance-critical part of the code, I need the ceiling of that floating-...
1
vote
1
answer
75
views
Why is && strict in compile time?
I am experimenting with basic template metaprogramming. I tried implementing structure templates which help us establish whether their template argument is prime or not. I.e.:
template<int N, int D&...
0
votes
1
answer
466
views
Null safety in dart (Null check operator used on a null value)
Hello i know it is very common error in flutter when we deal with dart null safety. I have come to know why this error is occuring but i am unable to fix this error."Null check operator used on a ...
10
votes
1
answer
203
views
What are "extern char condition tricks"?
I was reading the GCC documentation on C and C++ function attributes. In the description of the error and warning attributes, the documentation casually mentions the following "trick":
...
3
votes
1
answer
93
views
Make C++ preprocessor add a character at the end of each line
I am implementing some compile-time check which should base on a CSV file and I am trying to load it a bit hacky way:
constexpr std::variant<int, const char*> test[] = {
#include "data.csv&...
1
vote
0
answers
69
views
static_assert doesn't fire on MSVC
The below example code fires the "testing" assert with gcc and clang, but not MSVC. Only when the line marked comment this out is commented out does it fire. With GCC and clang it fires both ...
1
vote
1
answer
79
views
template instantiation via a function parameter in C++?
I have a class template which takes a compile time string as the template parameter. For example
template<size_t Size>
struct Buffer
{
char buffer[Size] = {0};
consteval Buffer(const ...
0
votes
1
answer
98
views
Nim - Norm - How to get related fieldnames at compile time
Heyho,
I am using norm, an orm in the nim programming language.
I have 2 different models such as this:
import std/options
import norm
type
A {.tableName: "Surprise".} = ref object of ...
0
votes
1
answer
72
views
Array constant not evaluating to constant even though only constexpr functions called in initialization
This is a simplified, reproducible version of my code:
type_id.h
template<typename>
void type_id() {}
typedef void(*type_id_t)();
c_sort.h (based on this answer)
template<typename Array>
...
0
votes
1
answer
79
views
Can C standard library functions with constant argument(s) be executed at compile time?
Can the following code:
float f = sinf(0.5f);
be optimized to the following code (actually pseudocode to give an idea):
float f = 0x1.eaee88p-2f;
feraiseexcept(FE_INEXACT);
The same principle for ...
0
votes
0
answers
99
views
Does adding `final` keyword decrease compile time in Swift?
According to Increasing Performance by Reducing Dynamic Dispatch, addding 'final' keyword increase runtime performance by reducing dynamic dispatch.
I'm wondering if adding 'final' keyword will also ...