108 karma · joined Nov 17, 2012 (14y ago) · 63 submissions
31.
Cget: cmake package retrieval(github.com ↗)
49 points · by pfultz2 · 10y ago · 24 comments
comment 11y ago · link · parent
And in C++, it provides the same high-level expressiveness as in Python.
> the more you can use them to easily do complex things arcoss different domains quickly.
But the advantage of C++ is that those abstractions have almost no overhead.
> So, for example, Python may have a better algorithm
Actually, C++ has a complexity guarantee for all of its algorithms.
> but C++ may use the hardware more efficiently.
Well, the brilliance of what Stepanov did was to build general purpose algorithms with out taking away random access capabilities which is beneficial for hardware efficiency(even more so now with modern cpus).
comment 11y ago · link · parent
C++ provides `set_intersection` as well: http://en.cppreference.com/w/cpp/algorithm/set_intersection
comment 11y ago · link · parent
Serialization is beyond the scope of what I am talking about. I am talking about reading bytes from a serial port.
> In that way, when using Async for network sockets, the SerialPortHW concept wouldnt be involved at all
But that is my whole point about Asio being split into smaller libraries such as Asio.Core, Asio.Network, and Asio.SerialPort. So you can use Asio.SerialPort without needing Asio.Network.
> in many occasions such extra async framework or the streams are not used.
You didn't read and write bytes to the serial port? What did you use it for?
> it would be in a different concept not included in the current project.
Its important for the library to implement the same "concepts"(or type requirements) for better consistency and composability(the only exception is iostreams which is horrible for both usability and implementations).
comment 11y ago · link · parent
comment 11y ago · link · parent
That's backwards. A SerialPort library would depend on Asio since it defines sync and async streams and the utilities built around that. It seems bad design for a SerialPort library to reimplement those basic utilities.
A dependency manager allows for finer modularity. So instead, Asio could be split into multiple libraries: Asio.Core, Asio.Serial, Asio.Network, etc. Its ok we have to bring in two smaller libraries instead of one large libary, since we have a dependency manager to handle this for us.
Also, a lack of a dependency manager in C++ has lead to developing of large monolithic libraries. So instead of managing dependencies, the library gives you everything plus the kitchen sink, so the user won't need to use another library. Of course, this is not scalable.
The other side-effect from a lack of a dependency manager in C++ is the developing of unnecessary header-only libraries(like Boost.Signals2). This just slows down compilation.
A real viable dependency manager in C++ will be a game changer, and recently. there is a lots of serious talk about it. In fact, there are like 3 difference talks that are directly related to dependency managing at C++Now 2015.
39.
C++: Towards better error reporting with Fit and Clang(pfultz2.com ↗)
3 points · by pfultz2 · 11y ago · discuss
comment 11y ago · link · parent
This is true. Sentences without correct grammar are unparseable(like "he jumped didn't far"). A lot of people seem to confuse semantic or logic issues with grammar issues.
41.
Docker stores username/passwords in essentially plaintext(github.com ↗)
4 points · by pfultz2 · 11y ago · discuss
comment 11y ago · link · parent
#define IOD_DEFINE_SYMBOL(name) iod_define_symbol(name, _##name)
#define IOD_S(name) s::_##name
#define ZLANG_iod_define (IOD_DEFINE_SYMBOL)
#define ZLANG_iod_s (IOD_S)
And then compiling with `-DZLANG_NS=iod` you can call it like this: // Define symbols
$(define hello)
$(define message)
auto hello_api = make_api(
// The hello world procedure.
$(s hello) = [] () { return D($(s message) = "Hello world."); }
);
Also, ZLang can be supported without a need for a dependency on ZLang.43.
C++ Reflection in under 100 lines of code(pfultz2.com ↗)
1 points · by pfultz2 · 12y ago · discuss
comment 12y ago · link · parent
struct square
{
int x;
};
struct rectangle
{
int x;
int y;
};
boost::variant<square, rectangle> to_shape(int x, int y)
{
if (x == y) return square(x);
else return rectangle(x, y);
}
std::vector<std::pair<int, int>> unknowns = {
{5, 4},
{3, 2},
{4, 4}
};
auto shapes = unknowns | boost::adaptors::transformed(boost::fusion::make_fused(to_shape));
Of course, the structs are not polymoprhic and can't be printed out. I just left that out because it requires a little more code to do that. Obviously with haskell its much less code.I would very much be interested in the dependently typed version.
comment 12y ago · link · parent
http://pfultz2.github.io/Fit/doc/html/fix/
So you could implement a generic factorial like this:
auto factorial = fit::fix([](auto self, auto x) -> decltype(x)
{
return x == 0 ? 1 : x * self(x-1);
});46.
Alexandrescu speaks up on the infamous “static if considered” paper(forum.dlang.org ↗)
2 points · by pfultz2 · 12y ago · discuss
comment 12y ago · link · parent
template<typename T>
std::pair<T, std::vector<std::string_view>>
tokenize_string(T &&str);
So then it uses `std::forward` to conditionally move the string for rvalues, and `T` will be a reference to the original string for lvalues.comment 12y ago · link · parent
It may be more verbose in C++, but its not more complicated, and its definitely not "ridiculously" complicated.
> I just implemented something very similar in Common Lisp and it wound up being incredibly simple.
Maybe for you as a lisp programmer, but for me I find the lisp code incomprehensible.
comment 12y ago · link · parent
Actually, pipable is very similiar to haskell's `$` function. So a similiar thing is done to improve readability of chaining functions in functional languages as well.
> At any rate, the thing that's strange about it is how verbose and hackish everything is. It's obvious the language wasn't designed to do anything like this, so the only way you can incorporate features like this is with unnecessarily obtuse and complex blocks of code.
How is the code obtuse and complex? I am using fairly straightforward techniques. I understand that I am working around the lack of perfect capturing for lambdas, but it is not complicated or clever the workaround.
comment 12y ago · link · parent
It is really common for the `|` operator to be used for piping functions together. There are several libraries that support it: [Boost.Range](http://www.boost.org/doc/libs/1_56_0/libs/range/doc/html/ind...), [PStade Oven](http://p-stade.sourceforge.net/oven/doc/html/index.html), [Linq](http://pfultz2.github.io/Linq/), and [Streams](http://jscheiny.github.io/Streams/). Plus, its even being proposed as part of the ranges library in future C++: https://github.com/ericniebler/range-v3/blob/master/doc/D412...
So just as the bit shift operators in C++ also have the meaning of streaming in and out, the bitwise or also has the meaning of pipe, so this is should not at all be a suprise.
comment 12y ago · link · parent
That doesn't sound like good C++. Making everything a pointer or implementing polymorphism through pointers makes the code harder to reason about, and makes tighter coupling between interfaces and implementations.
comment 12y ago · link · parent
Futhermore, doing it by hand is not as simple, but still not very complicated. This just helps alleviate the boilerplate in defining pipable functions.
comment 12y ago · link · parent
auto r = select(where(numbers, [](int x) { return x > 2; }), [](int x) { return x * x; });
Because of nesting this can be hard to read(and even write). If we can make the function pipable, the above can be written like this: auto r = numbers | where([](int x) { return x > 2; }) | select([](int x) { return x * x; });
Which it is easier to see what this does. So this blogpost goes over how to implement an utility that will take care of the boilerplate involved in writing a function that can be pipable.It does take advantage of a lot of C++14 features to implement this such as such as vardiac templates, rvalue reference, generic lambdas, and auto type deduction, but those feature actually make it simpler. I have in the past implemented something similar for C++03 and the code looks awful with way too much noise.
> this is madness.
Why do you consider this madness?
Maybe my mind has already been warped by C++.
comment 12y ago · link · parent
comment 12y ago · link · parent
comment 12y ago · link · parent
auto q = LINQ(
from(z, boost::irange(1, std::numerical_limits<int>::max()))
from(x, boost::irange(1, z))
from(y, boost::irange(1, x))
where(x*x + y*y == z*z)
select(boost::fusion::make_vector(x, y, z))
);
for(auto&& x:q | linq::take(10)) std::cout << x << std::endl;
Hopefully, once we get ranges in the C++ standard library, we can add list comprehension to the language, perhaps something like this: auto q = [
for (z, std::irange(1, std::numerical_limits<int>::max()))
for (x, std::irange(1, z))
for (y, std::irange(1, x))
if (x*x + y*y == z*z)
boost::fusion::make_vector(x, y, z)
];
for(auto&& x:q | std::take(10)) std::cout << x << std::endl;comment 12y ago · link · parent
vector<int> squareVec(const vector<int>& v)
{
return LINQ(from(i, v) select(i*i)) | linq::to_container;
}
And also filtering out odd elements: vector<int> squareVecFiltered(const vector<int>& v)
{
return LINQ(from(i, v) where(i % 2 == 0) select(i*i)) | linq::to_container;
}