Skip to main content
Filter by
Sorted by
Tagged with
1 vote
2 answers
95 views

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 ...
val - disappointed in SE's user avatar
0 votes
1 answer
125 views

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 ...
Enlico's user avatar
  • 30.3k
0 votes
2 answers
97 views

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?): &...
kusok_kvarka's user avatar
3 votes
1 answer
99 views

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 ...
Enlico's user avatar
  • 30.3k
3 votes
1 answer
253 views

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 ...
Ronika Kashyap's user avatar
2 votes
3 answers
232 views

How to iterate over tuple in compile-time? problem code: #include <array> #include <cstddef> #include <tuple> namespace { class Solution { public: template <size_t ...
arniiiii_ua's user avatar
0 votes
1 answer
89 views

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; ...
Gusen14ka's user avatar
0 votes
2 answers
92 views

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 ...
Dave Clark's user avatar
0 votes
0 answers
65 views

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 ...
Enlico's user avatar
  • 30.3k
0 votes
2 answers
188 views

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 ...
bers's user avatar
  • 6,309
0 votes
1 answer
127 views

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 ...
Oersted's user avatar
  • 3,834
4 votes
4 answers
276 views

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 ...
Lluís Alemany-Puig's user avatar
2 votes
1 answer
119 views

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 ) // ...
phil5's user avatar
  • 21
4 votes
1 answer
146 views

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 ...
Taylor's user avatar
  • 2,157
0 votes
4 answers
253 views

I have commands list based on string and have function which needs to be called regarding per command. I'm thinking to use unordered_map to keep commands and functions. std::unordered_map<std::...
embeddedstack's user avatar
1 vote
1 answer
165 views

Over time my project compile time has increased. But I don't know where the longest compile time is. It's just a small application with only 2 translation units. One compiles to an exe and takes care ...
梁海濤's user avatar
3 votes
2 answers
125 views

I want to assert that an object JsonKey if constructed with a string that is known at compile time doesn't contain a quote. Here's what I have: LiveDemo #include<iostream> template <size_t N&...
glades's user avatar
  • 5,374
5 votes
1 answer
147 views

The following code is not possible to compile. I'm wondering why: #include <string> constinit std::string constinit_string; // WORKS constinit thread_local int my_int; // WORKS constinit ...
Zebrafish's user avatar
  • 16.3k
0 votes
1 answer
151 views

I'm trying to load a folder of animation frames at compile time. The frames are named like this: frame1.png, frame2.png, ... frameN.png. Unfortunately after trying multiple methods for a while, I have ...
Aatos Tapper's user avatar
3 votes
1 answer
140 views

I am trying to ban the inclusion of a list of header files from a source file, and thus preventing the dependency on classes defined in those headers. There are tricks of checking the header guard ...
DXZ's user avatar
  • 505
3 votes
1 answer
84 views

#include <iostream> #include <array> template <typename T, size_t Rows, size_t Cols> class Matrix { protected: std::array<std::array<T, Cols>, Rows> matrix; ...
Osama Ahmad's user avatar
  • 2,368
2 votes
2 answers
185 views

I have some embedded C code where I want to have a list of sine values. I have done something similar in C++ using a constexpr function that return an std::array outside of the main loop: #include <...
nanocat's user avatar
  • 23
0 votes
1 answer
139 views

is there any ways of making unique hashes for each variable in compile time. C++ allows block scopes which can result in same named variables inside one function so i cannot just do: #define MACRO(...)...
A A's user avatar
  • 41
2 votes
1 answer
153 views

I'm trying to implement a hash function that can be used at compile-time. To achieve this, I need to reinterpret a value (e.g., an int or a float) as its raw bytes. However, when using compile-time ...
X1ngChui's user avatar
  • 147
1 vote
2 answers
117 views

I want to store several different callable objects (different types) in a container (e.g. std::array) in order to invoke them later. Each callable has the same return type and the same amount and type ...
breiters's user avatar
  • 158
2 votes
1 answer
105 views

I'm working with some code that targets an unusual embedded system that requires distinct processor instructions to read from its read-only memory. For variables to be placed in said read-only memory, ...
Pharap's user avatar
  • 4,152
1 vote
1 answer
274 views

In Rust, it is possible to iterate over values of an array: const COOL_NUMBERS: [i32; 4] = [1, 3, 3, 7]; fn do_something_cool() { for number in COOL_NUMBERS { // ... } } But it is ...
K. A. Kusakov's user avatar
0 votes
1 answer
299 views

I have a constexpr function that calculates CRC at compile time. I need to create a map between CRCs that are generated by this function and string inputs and use them in runtime (Even better if it is ...
Bahram Pouryousefi's user avatar
1 vote
0 answers
123 views

I want to generate one const array of elements of type struct config; and enumeration enum pin;, which shall be used to index said array, from (configuration) definitions contained in two separate ...
user1806687's user avatar
3 votes
2 answers
120 views

I'm given a std::variant of several types. I would like to write a trait that gives another std::variant of the pointer of the types of the first. using MyVariant = std::variant<int, float>; ...
MaPo's user avatar
  • 887
0 votes
1 answer
151 views

I am learning C++ and if I have classes class Core {...} class Grad: public Core {...} then Core* p; Core& ref; may be Grad objects which is not determined at compile time but at runtime hence ...
user avatar
1 vote
1 answer
155 views

I'm trying to write an API that validates the runtime type of typescript variables. I'd like to record what type of variable the user is expecting at compile-time and validate it at runtime; ...
Gili's user avatar
  • 90.9k
0 votes
1 answer
257 views

How to implement a flat map using arrays when keys are known at compile time. Imagine I know my keys: enum class Asset { FONT, TEXTURE }; struct AssetContainer { }; Hence I could do: struct ...
SpeakX's user avatar
  • 427
1 vote
2 answers
89 views

I recently have hit a wall, and can't seem to find an elegant solution to my problem: I have different data structures of different number of elements, all of which are aligned to pointer-size and are ...
user2281752's user avatar
2 votes
2 answers
143 views

I am trying to make a writer class, which would be used to turn data into a binary stream, at compile-time using a std::vector, and then converting it to std::array to be used at runtime. eg: #include ...
user15137921's user avatar
0 votes
1 answer
142 views

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&...
YKS's user avatar
  • 3
0 votes
1 answer
187 views

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 { () =&...
yhw2003's user avatar
  • 17
0 votes
2 answers
112 views

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: ...
Zsar's user avatar
  • 493
3 votes
1 answer
94 views

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 ...
Readren's user avatar
  • 1,290
3 votes
1 answer
269 views

I am trying to make the following code work: #include <string> #include <tuple> #include <print> template<char Specifier> struct ParseSpecifier; template<> struct ...
Eshy's user avatar
  • 441
1 vote
2 answers
92 views

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 <...
X1ngChui's user avatar
  • 147
1 vote
2 answers
111 views

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 ...
Olli Niemitalo's user avatar
0 votes
2 answers
134 views

Consider having a simple class, that writes integers to cout depending on its state: #include <iostream> class NotAWriter{ public: NotAWriter& operator<<(const int& arg) { ...
MPEI_stud's user avatar
  • 135
2 votes
1 answer
70 views

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 ...
Readren's user avatar
  • 1,290
3 votes
3 answers
283 views

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 ...
Abdulmalek Almkainzi's user avatar
0 votes
1 answer
46 views

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'...
rjapenga's user avatar
  • 277
0 votes
1 answer
92 views

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>...
user23562328's user avatar
0 votes
2 answers
115 views

int f(auto obj) { if constexpr (HasFastGetData<decltype(obj)>) { return obj.FastGetData(); } else { return obj.GetData(); } } int main() { B obj; f(obj); ...
xmllmx's user avatar
  • 44.6k
9 votes
2 answers
346 views

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 ...
Oersted's user avatar
  • 3,834
0 votes
0 answers
35 views

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 <...
Sheldon's user avatar
  • 467

1
2 3 4 5
20