[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: bongo-cat-typing.gif (26 KB, 410x640)
26 KB
26 KB GIF
I love C++! :D
#include <iostream>
#include <type_traits>

/**
* @brief Generic meta-combinator for layered template evaluation.
*
* Combines two template-level value providers (A and B) to enable
* multi-phase compile-time composition.
*/
template<template<typename> class A, template<typename> class B, typename T>
struct Combine {
using type = typename B<T>::type;
static constexpr auto value = A<T>::value + B<T>::value;
};

/**
* @brief Base meta-wrapper exposing a compile-time value.
*/
template<typename T>
struct Wrapper {
using type = T;
static constexpr T value = 0;
};

/**
* @brief Incremental meta-transformer providing a constant offset.
*
* Can be extended for custom numeric promotion logic.
*/
template<typename T>
struct Increment {
using type = T;
static constexpr T value = 1;
};

/**
* @brief Higher-level aggregation of template-based numeric traits.
*
* Demonstrates meta-layered composition patterns using
* template-of-template parameters.
*/
template<template<typename> class A, template<typename> class B, typename T, int N>
struct Final : Combine<A, B, T> {
static constexpr auto value = Combine<A, B, T>::value + N;
using type = typename Combine<A, B, T>::type;
};

int main() {
using Computation = Final<Increment, Wrapper, int, 41>;
std::cout << Computation::value << std::endl;
}
>>
>>106996545
Nice one anon. Would it be possible to define operators on Combine and use them within a declval?
It would be nicer than declaring lots of nested templates when declaring the alias
>>
File: 1761233310018940.png (53 KB, 910x1024)
53 KB
53 KB PNG
>>106996545
I love C#

using System;

// Generic meta-combinator for layered evaluation
public class Combine<A, B, T> where A : IValueProvider<T>, new() where B : IValueProvider<T>, new()
{
public static Type Type => typeof(B).GetProperty("Type").GetValue(null) as Type;
public static T Value => (T)(object)(new A().Value + new B().Value);
}

// Interface to mimic meta-wrapper behavior
public interface IValueProvider<T>
{
T Value { get; }
Type Type { get; }
}

// Base meta-wrapper exposing a compile-time value
public class Wrapper<T> : IValueProvider<T>
{
public T Value => default(T); // Equivalent to 0 for numeric types
public Type Type => typeof(T);
}

// Incremental meta-transformer providing a constant offset
public class Increment<T> : IValueProvider<T> where T : struct
{
public T Value => (T)(object)1; // Assumes T is numeric, constant offset of 1
public Type Type => typeof(T);
}

// Higher-level aggregation of template-based numeric traits
public class Final<A, B, T, const int N> : Combine<A, B, T>
where A : IValueProvider<T>, new()
where B : IValueProvider<T>, new()
{
public static new T Value => (T)(object)(((dynamic)Combine<A, B, T>.Value) + N);
public static new Type Type => Combine<A, B, T>.Type;
}

class Program
{
static void Main()
{
// Using int as the type for computation
var value = Final<Increment<int>, Wrapper<int>, int, 41>.Value;
Console.WriteLine(value); // Outputs 42
}
}
>>
>>106996545
recently I decided to start a new project in a modern c++ standard to use things like concepts and the std::views stuff, but it's a clusterfuck. to use concepts and any kind of templates even, you need to implement everything on the header. and the ranges library is a mess, extremely verbose and non-intuitive names for the sake of being different.
>>
yea man fucking around with types and abstractions is so useful
>>
>>106996545
Breddy cool, ngl fr fr.
>>
>>106996545
How does one know they need a “Generic meta-combinator for layered template evaluation”

Usually, even on simple programs, I make sure I use every feature, and planned feature that might be partially implemented by clang or gcc. Otherwise you’re not getting the true value of C++.
I have worked many thousands of hours on this programming, but have never released anything, and most of it won’t compile anymore.
>>
>>106998761
Sounds like a sub-theme for the movie "Idiocracy". You could do this for physical engineering too. Electrical systems that don't work. Cars that don't work. Building construction that doesn't work, etc.
>>
>>106998615
> implement everything on the header
I’ve stopped using .cpp files altogether and use the template system and preprocessor as an interpreter. Just the act of “compiling” the .h files is the computation itself, and now I don’t need any object files or binaries.

I’m considering trying visual basic as I hear it’s the same thing but faster with a better syntax.
>>
Lol.

Surely the 1337 Designs ITT with lead to the AGI breakthroughs we all hope for!111
>>
File: caca.jpg (39 KB, 500x375)
39 KB
39 KB JPG
>>106998495
>dynamic
lmao
nice try, faggot
>>
>>106998797
the bad thing is that it recompiles the header every time it's included, or so I heard. I don't think it would affect me immediately (I ended up writing what I wanted in C and it's at 3000 lines right now, around 10 .c+.h files, so not much) but it's certainly something to keep in mind if you want your project to be non trivial.
this is specially true if you make heavy usage of templates and constexpr
>>
File: 1600614752898.png (867 KB, 1097x912)
867 KB
867 KB PNG
>>106996545
What does this do? Why would this ever be useful?
>>
File: 1739777887886.jpg (82 KB, 900x900)
82 KB
82 KB JPG
>>106998761
Precisely
>>
>>106998824
Kek. The irony isn't it. Especially given neural nets running on GPUs are a runtime implementation and not compiletime.
>>
>>106996545
>meta-combinator for layered template evaluation
lol if this combination of 'words' doesn't make you immediately turn 360° and walk away
>>
>>106998649
ikr, fuck abstraction
110001010102110111110101010101010000010
>>
>>106998893
Yes, I was being ironic. Thought I'd point that out, given Poe's Law & watnot.

Imagine if a racing machine team attempted to use this sort of hogwash for their cars: >>106998761
They'd be laughed off the track and barred.

Good results start with good designs. Throwing shite against the wall hoping something will stick is nigger-tier...or worse: poojeet-tier thinking.
>>
>>106996545
Anybody who defines template templates is probably insane, and that's corroborated by this code. I've only used them once in 10 years and that was a toy setup



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.