Remix.run Logo
Lisp-style C++ template meta programming(github.com)
41 points by mistivia 10 hours ago | 7 comments
pjmlp 21 minutes ago | parent | next [-]

While cool for those stuck in C++17, which are plenty given the C++ version of "can I use", C++26 should make many of these approaches more easily available.

However it is still a few years away to be widely deployed, and a few niceties have been postponed into C++29.

jjmarr 43 minutes ago | parent | prev | next [-]

if this is a C++17 library why couldn't you use `constexpr` evaluation and not murder your compilation time?

mistivia 18 minutes ago | parent | next [-]

Template metaprogramming isn't really suited for this task, the prime sieve here serves only as a proof of concept, meant to show the capabilities of this style. But there are cases where `constexpr` is not applicable, especially when involving type manipulations.

On the other hand, C++ template metaprogramming, as an esolang, is fun to tame and experiment with.

jjmarr 7 minutes ago | parent [-]

Is there a clearer example where constexpr wouldn't work?

> On the other hand, C++ template metaprogramming, as an esolang, is fun to tame and experiment with.

Is it an esolang at this point? I feel old.

pjmlp 23 minutes ago | parent | prev [-]

I imagine because some of the cool constexpr improvements are only available in C++20 and C++23.

ahartmetz 3 hours ago | parent | prev [-]

That could be pretty cool, I wonder what it does for compile time though.

alex_dev42 2 hours ago | parent [-]

Good point about compile time. Template metaprogramming can definitely impact build performance, especially with recursive template instantiation.

From what I've seen in the repo, this approach might actually help with compile times in the long run. The Lisp-style syntax could enable better template caching and memoization strategies compared to the nested template<template<...>> patterns we usually see. Plus, cleaner metaprogramming code means developers are less likely to write deeply nested recursive templates that blow up compile times.

Would be interesting to see some benchmarks comparing compile times for equivalent functionality written in traditional C++ template style vs this approach.