Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"02-14-15 - Template Arithmetic Coder Generation"

4 Comments -

1 – 4 of 4
Blogger won3d said...

Since this is for development and not for code that would ever actually ship, I wonder how good you could get things by using conventional constants rather than template parameters.

You get a structural win in that commensurate patterns are automatically reflected in the encode/decode methods...but those being the only two methods that really need to be in sync somewhat blunts the benefit since you are essentially trading off 2x repetition for having to deal with template metaprogramming. The essential dilemma is that you really do want metaprogramming sometimes, but C++ template metaprogramming is such a bad option a lot of times. I sure wish it weren't!

February 16, 2015 at 12:21 PM

Blogger cbloom said...

Well, you can't actually use constants because constants in C aren't properly compile-time.

(they should be)

If constants were better in the compiler, and branches that evaluated to

if ( false )

were not even attempted to be compiled, then you could do a lot more with just constants.


Some of the stuff here could be done with macros, things like ENCODE_VAL_SPLIT / DECODE_VAL_SPLIT , sure could be macros. But IMO macros just worse than templates in almost every way except compile time and they optimize better.

Some of the stuff here can't be done with anything but templates, like bitwise_split_coder which is recursive and requires the template-specialization-termination trick.

February 16, 2015 at 12:29 PM

Blogger cbloom said...

And more generally -

I actually think C++ templates are fantastic for little isolated things like this.

As long as you can write them in one file and use them in that file, they're super nice and useful. I use them for things like generating image compressors that can work on different pixel formats.

The place where templates really fall apart (IMO) is when you try to use them as a fundamental architecture and get them in your shared headers and they start crudding up your whole compile.

February 16, 2015 at 12:31 PM

Blogger won3d said...

"As long as you can write them in one file and use them in that file, they're super nice and useful."

Yeah, I guess the key to sanity is some kind of isolation discipline.

February 16, 2015 at 12:37 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.