Skip to content

Commit f3d4126

Browse files
committed
Un-recommend the baseNN_default_* headers.
They introduce complexity, make autocompletion more cumbersome, and shouldn't be included in other header files because they pollute the global namespace. If people copy base64 code from one file to the other, the meaning of the code can change based on which default header is included, which is not great. I thought they added convenience, but actually, including them makes cppcodec worse (probably). So the first thing I can do is to stop recommending these headers. The second thing will be to deprecate them. This may or may not happen, I have to contemplate if the work inflicted on users for changing header files outweighs the benefit of not having too many "wrong" templates in other GitHub projects. Either way, no new default headers will be added to cppcodec.
1 parent 2d054bb commit f3d4126

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,31 @@ Alternatively, you can install the headers and build extra tools/tests with CMak
2626

2727
A number of codec variants exist for base64 and base32, defining different alphabets
2828
or specifying the use of padding and line breaks in different ways. cppcodec is designed
29-
to let you make a conscious choice about which one you're using, but assumes you will
30-
mostly stick to a single one.
29+
to let you make a conscious choice about which one you're using, see below for a list of variants.
3130

32-
cppcodec's approach is to implement encoding/decoding algorithms in different namespaces
33-
(e.g. `cppcodec::base64_rfc4648`) and in addition to the natural headers, also offer
34-
convenience headers to define a shorthand alias (e.g. `base64`) for one of the variants.
31+
cppcodec's approach is to implement encoding/decoding algorithms in different classes for namespacing (e.g. `cppcodec::base64_rfc4648`), with classes and their associated header files named verbatim after the codec variants.
3532

3633
Here is an expected standard use of cppcodec:
3734

3835
```C++
39-
#include <cppcodec/base32_default_crockford.hpp>
40-
#include <cppcodec/base64_default_rfc4648.hpp>
36+
#include <cppcodec/base32_crockford.hpp>
37+
#include <cppcodec/base64_rfc4648.hpp>
4138
#include <iostream>
4239

4340
int main() {
44-
std::vector<uint8_t> decoded = base64::decode("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
45-
std::cout << "decoded size (\"any carnal pleasure\"): " << decoded.size() << '\n';
46-
std::cout << base32::encode(decoded) << std::endl; // "C5Q7J833C5S6WRBC41R6RSB1EDTQ4S8"
47-
return 0;
41+
using base32 = cppcodec::base32_crockford;
42+
using base64 = cppcodec::base64_rfc4648;
43+
44+
std::vector<uint8_t> decoded = base64::decode("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
45+
std::cout << "decoded size (\"any carnal pleasure\"): " << decoded.size() << '\n';
46+
std::cout << base32::encode(decoded) << std::endl; // "C5Q7J833C5S6WRBC41R6RSB1EDTQ4S8"
47+
return 0;
4848
}
4949
```
5050

51-
If possible, avoid including "default" headers in other header files.
51+
(The prior example included "baseXX_default_*.h" includes, these are not recommended anymore and may eventually get deprecated.)
5252

53-
Non-aliasing headers omit the "default" part, e.g. `<cppcodec/base64_rfc4648.hpp>`
54-
or `<cppcodec/hex_lower.hpp>`. Currently supported variants are:
53+
Currently supported codec variants are:
5554

5655
### base64
5756

tool/helloworld.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
* For more information, please refer to <http://unlicense.org/>
2525
*/
2626

27-
#include <cppcodec/base32_default_crockford.hpp>
28-
#include <cppcodec/base64_default_rfc4648.hpp>
27+
#include <cppcodec/base32_crockford.hpp>
28+
#include <cppcodec/base64_rfc4648.hpp>
2929
#include <iostream>
3030

3131
int main() {
32-
std::vector<uint8_t> decoded = base64::decode("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
33-
std::cout << "decoded size (\"any carnal pleasure\"): " << decoded.size() << '\n';
34-
std::cout << base32::encode(decoded) << std::endl; // "C5Q7J833C5S6WRBC41R6RSB1EDTQ4S8"
35-
return 0;
32+
using base32 = cppcodec::base32_crockford;
33+
using base64 = cppcodec::base64_rfc4648;
34+
35+
std::vector<uint8_t> decoded = base64::decode("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
36+
std::cout << "decoded size (\"any carnal pleasure\"): " << decoded.size() << '\n';
37+
std::cout << base32::encode(decoded) << std::endl; // "C5Q7J833C5S6WRBC41R6RSB1EDTQ4S8"
38+
return 0;
3639
}

0 commit comments

Comments
 (0)