[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

See 8chan's new software in development (discuss) (help out)
Advertise on this site
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


8df5b4 No.2850

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;
}
};

8df5b4 No.2851

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

Forgot image.


a41b12 No.2867

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?


a202be 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.


19ca3f 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.


79e31e 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.


32f0e4 No.3280

> ruin time


1df108 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][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]