markdown jeej
This commit is contained in:
parent
47557ea5f6
commit
093e50fa3f
5 changed files with 43 additions and 30 deletions
|
@ -1,5 +1,10 @@
|
||||||
|
it works
|
||||||
|
========
|
||||||
|
(at least i hope so...)
|
||||||
|
|
||||||
|
|
||||||
Here are some (hopefully useful) c++ snippets/libs/helperthingies.
|
Here are some (hopefully useful) c++ snippets/libs/helperthingies.
|
||||||
|
|
||||||
Probably all are header only, with a main.cpp for testing.
|
Probably all are header only, with a main.cpp for testing.
|
||||||
Stuff probably needs some C++0x features.
|
Stuff probably needs some *C++0x* features.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
Usage:
|
Usage:
|
||||||
|
======
|
||||||
|
|
||||||
std::cout << make_binary(1337) << make_binary("a c-style array");
|
std::cout << make_binary(1337) << make_binary("a c-style array");
|
||||||
will output binary representations of shizzle.
|
will output binary representations of shizzle.
|
||||||
|
|
||||||
Make sure your type is copyable by just copying it's memory-region.
|
Make sure your type is copyable by just copying it's memory-region.
|
|
@ -1,23 +1,25 @@
|
||||||
Usage:
|
Usage:
|
||||||
|
======
|
||||||
|
```C++
|
||||||
brainfuck("++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.");
|
brainfuck("++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.");
|
||||||
The default arguments make it use std::cout and an empty string as input.
|
```
|
||||||
|
The default arguments make it use `std::cout` and an empty string as input.
|
||||||
|
|
||||||
|
|
||||||
You can also use a string as input:
|
You can also use a string as input:
|
||||||
brainfuck(",[.,]", "input");
|
brainfuck(",[.,]", "input");
|
||||||
|
|
||||||
Or with a stream/container/iterator:
|
Or with a stream/container/iterator:
|
||||||
brainfuck(",[.,]", std::input_iterator<char>(std::cin));
|
brainfuck(",[.,]", std::input_iterator<char>(std::cin));
|
||||||
|
|
||||||
|
|
||||||
You can specify the memory-units:
|
You can specify the memory-units:
|
||||||
brainfuck<int>("...");
|
brainfuck<int>("...");
|
||||||
As long as the type has certain operators. The default output is comma-seperated, except for char.
|
As long as the type has certain operators. The default output is comma-seperated, except for char.
|
||||||
|
|
||||||
|
|
||||||
You can specify an output-iterator:
|
You can specify an output-iterator:
|
||||||
brainfuck("...", "", std::back_inserter(my_vector));
|
brainfuck("...", "", std::back_inserter(my_vector));
|
||||||
|
|
||||||
|
|
||||||
It has a lot of defaultparameters, because it's intended use was on an irc-channel.
|
It has a lot of defaultparameters, because it's intended use was on an irc-channel.
|
|
@ -1,22 +0,0 @@
|
||||||
counted
|
|
||||||
=======
|
|
||||||
|
|
||||||
"for(auto x : counted(v)) { ... x.value ... x.index ... }"
|
|
||||||
x.value is a reference to the element in the container (so you can change it's value), x.index is what it is.
|
|
||||||
Container should have forward iterators.
|
|
||||||
|
|
||||||
|
|
||||||
This headers is purely a handy tool for the range-based-for-loops (ie "for(auto x : counter(v))"). Using it explicitly with iterators is not recommended!
|
|
||||||
|
|
||||||
|
|
||||||
There is no const version of it. Doing "for(const auto x : counted(v))" doesn't make it impossible to change x (so the element in the container can be modified).
|
|
||||||
|
|
||||||
|
|
||||||
Example:
|
|
||||||
for(auto x : counted(v)) {
|
|
||||||
std::cout << "v[" << x.index << "] = " << x.value << std::endl;
|
|
||||||
x.value *= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
This will output the container v, with it's indeces. And it will multiply every value in v by 2.
|
|
||||||
|
|
27
iterators/README.md
Normal file
27
iterators/README.md
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
counted
|
||||||
|
=======
|
||||||
|
|
||||||
|
```C++
|
||||||
|
for(auto x : counted(v)) {
|
||||||
|
... x.value ... x.index ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
`x.value` is a reference to the element in the container (so you can change it's value), `x.index` is what it is.
|
||||||
|
Container should have forward iterators.
|
||||||
|
|
||||||
|
|
||||||
|
This headers is purely a handy tool for the range-based-for-loops (ie `for(auto x : counter(v))`). Using it explicitly with iterators is not recommended!
|
||||||
|
|
||||||
|
|
||||||
|
There is no const version of it. Doing `for(const auto x : counted(v))` doesn't make it impossible to change `x` (so the element in the container can be modified).
|
||||||
|
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```C++
|
||||||
|
for(auto x : counted(v)) {
|
||||||
|
std::cout << "v[" << x.index << "] = " << x.value << std::endl;
|
||||||
|
x.value *= 2;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
This will output the container `v`, with it's indeces. And it will multiply every value in `v` by 2.
|
||||||
|
|
Reference in a new issue