October 22, 2024
Chicago 12, Melborne City, USA

templates

used in multiple contexts: generic programming (especially C++), and data/document generation using template engines, web template

templates

Template deduction guide doesn't work well with aggregate initialization

I am studying how to use deduction guides. I composed this program. template<typename T> struct Test { void f() { cout << std::is_same_v<T, std::size_t> << endl; } T t; }; Test(int) -> Test<std::size_t>; int main() { Test t1(1.2); t1.f(); } I expected the deduction guide will only kick in when if I pass an integer

Read More
templates

Why is void_t used in SFINAE?

I intend for my question to be a follow up to: How do we use void_t for SFINAE?. I understand how void_t is used. I do not understand why it is necessary. Let’s take the example from that SO question and remove the void_t template< class , class = void > struct has_member : std::false_type

Read More
templates

(Reverse) forwarding consteval-ness of constructor with perfect forwarding

Let’s say I have a class with a consteval constructor that ensures a valid value at compile time. (There’s also a std::expected-returning factory method that validates its argument at runtime, but that’s irrelevant for this question.) class ConstevalConstructible { public: consteval ConstevalConstructible(int value) : value_(value) { // Validate value and fail compile if invalid. }

Read More
templates

Uncaught ReferenceError: iziToast is not defined

{{define "scripts"}} <script src="/admin/assets/js/iziToast.min.js"></script> <script> iziToast.show({ title: 'Hey', message: 'What would you like to add?' }); </script> {{end}} Although I define it as a script, I cannot get the message on the site when I run it. I was expecting ‘What would you like to add?’ but I get ‘Uncaught ReferenceError: iziToast is not defined’

Read More
templates

Overload resolution of const and non-const function fails on template

In the following code, when calling arr.begin() on a const Array<10> object, it fails to find the const function Accessor::begin() const, and instead only tries MutableAccessor::begin() and fails because arr is const. When using arr.cbegin(), it works correctly. Also when both the const and non-const overload of a function are defined in the same class,

Read More
templates

Functions chaining with std::tuple

I’m trying to implement functions chain, that get bunch of different functions and member functions at compile time and execute them one by one and stop execution if processing function fails. It may be any count of functions. Now I’m stuck on the fact that std::tuple::get doesn’t accept counted variable as template parameter. How can

Read More
templates

WPF Custom TextBox Sizing issue

I am trying to create a custom TextBox Template in WPF. My TextBox has a 1px border around it, this border has a margin of 8px, this is all simple stuff, no issues here. The issue I have is that when I use my TextBox and define: <TextBox Template="MyTextBoxTemplate" Height="100"> The actual output height of

Read More
templates

Issue calling a variadic template constructor

The following code doesn’t work, it fails because it cannot find a constructor with a <int, bool> signature. I know can’t specify explicitely the template parameters in the case of a constructor. Why does it fail template parameter deduction? Is there any way to make it work? I know I can use a template factory

Read More
templates

Is it possible to insert fields from a commit in the github pull_request_template?

When I create a PR, I first created a branch and committed changes. With the commits I have fields such as: a description (comment/message) the commit UUID the date / time when the commit happened others… My main problem, at the moment, is the comment from the first commit appears BEFORE the template. I’d like

Read More
templates

Class deriving from virtual pure, auto generation of override from a template

I’m using the Subject/Observer pattern in a way that I have a class observing 2 kinds of event: class manager : public observer<eventA>, observer<eventB> To be valid, the manager class must implement an Update function for each event type, but what could I do if those functions can basically be written by a template? So,

Read More