Here is some fun with C++11's constexpr. It seems we can check substring containment at compile time. The following example works fine with GCC 4.6.1.
#include <iostream>
#include <array>
constexpr bool not_end(const char *s, const int n) {
return s && s[n];
}
/* does `s` have `t` as prefix. Use offsets ns, nt */
constexpr bool str_prefix(const char *s, const char *t, const int ns, const int nt) {
return (s == t) || !*(t + nt) || (*(s + ns) == *(t + nt) && (str_prefix(s, t, ns+1, nt+1)));
}
constexpr int contains1(const char *s, const char *needle, const int n) {
return not_end(s,n) && (str_prefix(s, needle, n, 0) || contains1(s, needle,n+1));
}
constexpr int contains(const char *s, const char *needle) {
return contains1(s, needle, 0);
}
const int x = contains("froogler", "oogle");
int main(void) {
std::array<int, 10 * contains("hi there", "the")> a;
std::array<int, 10 * contains("hi thre", "the")> b;
std::cout << "Array size for a is " << a.size() << "\n";
std::cout << "Array size for b is " << b.size() << "\n";
std::cout << "x: " << x << "\n";
}
It compiles without warnings using the commandline:
g++ -Wall -std=c++0x -o constarray constarray.cc
And produces the following output:
Array size for a is 10 Array size for b is 0 x: 1
So, is this a legal part of C++11? Is it a good thing? It is at least a more readable compile-time language than template metaprogramming.
If you want to contact me, I'm @englabenny on twitter
Edit to add a Bonus: an implementation of foldr over initializer lists, see C++ constexpr foldr
Posted Friday afternoon, October 21st, 2011Are you wondering about the ascii icons?
Then you should look here
Great Artists Steal
Via a totally custom plugin you can tell Kupfer to use some icons from Quicksilver's repository. This is what it looks like: (qsicons branch on github.)
A big thank you to all that participated in the 1st of April beta testing stint of Kupfer's version v205. It has been decided that we can deliver a superior experience to our users if we discontinue the ASCII icon set in future releases. The ASCII icon set will however remain as an plugin.
Stay tuned for kupfer v206 this coming week which will include the final bug fixes and translations. Don't hesitate take part in bugreporting.
Finally, I kindly ask you to consider donating to me for my work on Kupfer. There is a donation button on the main web page for kupfer.
(The dude in preferences can be found here and the 1st of April kupfer website is here.)
Posted in the wee hours of Friday night, April 2nd, 2011Finally, kupfer is released with the latest version v205. This is a really nice release, a bit of a prerelease actually; we simply can't let the new stuff wait in a stable branch until it gets cold.
We are adding all the things we promised when posting the latest version (Welcome to Kupfer v204), and more than that as well. Please report any bugs that you find.
Feedback & comments to @englabenny on twitter or @kaizer on identi.ca, or use hashtag #kupfer. The Kupfer project itself also has a mailing list, and we have an irc channel on irc.freenode.net #kupfer as well.
Posted at midnight, April 1st, 2011Finally, kupfer is released with the latest version v204. Many small or large bugs and problems have been fixed and we are also introducing some useful new stuff.
First and foremost, I hope that the expanded Kupfer User Manual will be a great help to new and old users. It includes a keyboard shortcuts reference, lots of tips and basic usage help for the most important plug-ins. Kupfer has been lacking in documentation and hopefully it will grow larger with time. Also thanks to the awesome translators of the documentation, and of Kupfer as a whole!
Highlights
- Gwibber integration by Karol
- Empathy integration by Jakh Daven
- Better integration with commmand-line tools, including passing text from and to shell scripts. Thanks @hetdegon for requesting this feature!
See the full changelog for details: v204
Future Kupfer
The next kupfer version is already in the works and it will solve some of the deeper or more long-running problems.
Turn to the development version (post-v204) for improved user interface, ibus support and terminal configuration.
Feedback & comments to @englabenny on twitter or @kaizer on identi.ca, or use hashtag #kupfer. The Kupfer project itself also has a mailing list
Posted Friday evening, March 18th, 2011