[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][Options][ watchlist ]

/prog/ - Programming

Programming board

Catalog

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

[–]

aa0b76 (2) No.2850[Watch Thread][Show All Posts]

Let's talk about compile time programming. Do you find it useful? Do you even use it?

I've been scratching the surface since I have not really needed to use it but I've become more aware of the importance of doing calculations at compile time rather than during ruin time. Here are compile time strings:


#include <string>

class CTString{

private:

const char* const p_chars;
const std::size_t _size;

public:

template<std::size_t N>
constexpr CTString( const char(&p_Chars)[N] ):p_chars(p_Chars),_size(N-1){
}
constexpr char operator[]( std::size_t N ){
return N < _size ? p_chars[N]: throw std::out_of_range("");
}
constexpr std::size_t size(){
return _size;
}
constexpr const char* const str(){
return p_chars;
}
};

aa0b76 (2) No.2851

File (hide): 1437199916727.png (330.17 KB, 400x400, 1:1, welcome to metaprogramming.png) (h) (u)

Forgot image.


70df11 (1) No.2867>>3112

I often have to grit my teeth using a language that isn't really built for metaprogramming. I'll start off writing things in a certain way, but then realize that it will just become a nightmare to deal with and it would be easier doing it in the standard way.

I am yet to try a language that isn't a Lisp which makes non-trivial metaprogramming relatively simple. Anyone have any suggestions?


818edc (1) No.2869

it's pretty cool but i hardly use it.

crytek makes excessive use of it, e.g. for their RPC functions. when working with the freesdk i realized IDEs really suck at dealing with that kind of thing, took me some time to figure out how and where functions were declared and defined.


d4670c (1) No.3112

>>2867

forth is great for meta programming



\ extra registers
create rn 8 cells allot
: @rn @ rn + ;
: ldn ( n -- | -- n ) create , does> @rn @ ;
: stn ( n -- | n -- ) create , does> @rn ! ;
: regacc dup ldn stn ;
0 regacc ld0 st0
1 regacc ld1 st1
2 regacc ld2 st2
3 regacc ld3 st3
4 regacc ld4 st4
5 regacc ld5 st5
6 regacc ld6 st6
7 regacc ld7 st7

Is some code I just wrote.


d673b2 (1) No.3126

C++ templates are great until you destroy your first project with them. It's a race to see what will kill it first: code bloat or compile time. Experiment with them and see what the overhead is. I guarantee you'll be shocked as no one believes they're so prone to these problems until you force their eyes open.


4347e7 (1) No.3280

> ruin time


6e2db8 (1) No.3467

I almost always use it with types in C++ to make some functions and comparisons more generic- i.e compare by an attribute of a class or struct instead of operator overloading. However, not much beyond that.

For example:


template <typename OBJ, typename ATTR>
void bytype(const ATTR OBJ::*p, const vector<OBJ>& input)

bytype<Struct, string>(&Struct::attribute, data);




[Return][Go to top][Catalog][Screencap][Update] ( Scroll to new posts) ( Auto) 5
7 replies | 1 images | 7 UIDs | Page ?
[Post a Reply]
[ / / / / / / / / / ] [ dir / ask / dcaco / fur / hypno / o / sl / ttgg / u ][ watchlist ]