-
Notifications
You must be signed in to change notification settings - Fork 632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port to C++14 #66
Comments
"Important: Before GCC 5.1 support for C++11 was experimental. Some features were implemented based on early proposals, and no attempt was made to maintain backward compatibility when they were updated to match the final C++11 standard." - https://gcc.gnu.org/projects/cxx0x.html I use c++11 features on Ubuntu 14.04(gcc 4.8.4) and it is usable. It's worth noting that gcc 5.1 is the compiler used in Ubuntu 15.10. Ubuntu 16.04 LTS will probably use 5.3. Unfortunately, gcc 6 will probably not be ready before the 16.04 LTS, which will have gnu++14 as the default c++ dialect. I believe gcc 5.1 still defaults to gnu++98, so you'll have to add -std=gnu++11. |
Thanks for the info! I think that the limiting factor seems to be gcc in Ubuntu precise 12.04 (which we support in our PPA), which is supported until 2017/04 and comes with gcc 4.6.3. |
CPipe uses std::auto_ptr which is deprecated in c++11. Not only is the warning annoying, but std::auto_ptr will be removed in c++17. Version 2.0.0 would probably be a good time to change that interface. It might work to template that method. It should maintain compatibility to older code. typedef std::shared_ptr<CPipeWriteEndPoint> CPipeWriteEndPointPtr;
typedef std::shared_ptr<CPipeReadEndPoint> CPipeReadEndPointPtr;
template <typename ReadPtr, typename WritePtr>
static void createPipe(ReadPtr &outReadPipe, WritePtr & outWritePipe)
{ |
Thanks for the idea! Also, you may have noticed that as a workaround to avoid those warnings I opened #235 , because CPipe is actually used in only a couple of places in the entire mrpt... |
@jlblancoc probably want to add "support move semantics" Sometimes you get move implicitly. Here are the rules.
Eigen should support move already, but I don't think any mrpt classes have an explicit move constructors. It's very easy to break one of those above rules without realizing it. Probably the best place to start is to see if everything derived from CArrayNumeric supports move. |
Thanks! I added that to the list in the issue text above. Indeed, that should be done to allow users exploit move semantics. If you have an idea of how to perform a generic compile-time or runtime test that fails if the "move" op. does not happen, we would add it to be done as part of the unit tests, just like it's done now with serialization ;-) |
It's already in the standard. This should give you good error messages: #include <type_traits>
struct CannotMove
{
CannotMove(const CannotMove &)
{}
CannotMove(CannotMove &&) = delete;
};
struct CannotCopy
{
CannotCopy(CannotCopy &) = delete;
CannotCopy(CannotCopy &&){};
};
template<typename T>
class ConstructorTests{
static_assert(std::is_move_constructible<T>(), "Can't move");
static_assert(std::is_copy_constructible<T>(), "Can't copy");
};
template class ConstructorTests<CannotMove>;
template class ConstructorTests<int>;
template class ConstructorTests<CannotCopy>; gcc
clang
Might want to add Also this might be useful for some specific tests.
|
Brilliant! BTW: I just created a 2.0-devel branch to slowly start pushing changes there. |
@jlblancoc It does look like there are some issues with move as shown by my pull request.
|
@jlblancoc: Might as well add c++17 to the list since they will be adding parallel policies. http://en.cppreference.com/w/cpp/algorithm I think those would be preferred over Intel TBB based solutions. |
How can I join this initiative? |
@olzhas Take a look at the 2.0 branch. I would really like to see stlplus shared_ptr replaced with std::shared_ptr. Let me know if you need any help. |
By the way, this transition would be the perfect occasion to also add to
each CObject, but only the ::Ptr start pointer as it is now, buy also a
::ConstPtr to const pointers, as in PCL, for example.
This change would start in the macros in CObject.h
|
Agreed, I think supporting const will be a great second step. There's quite a lot of infrastructure with CObject which may make binding pointers smart pointers of different types a bit tricky, so I didn't want to overwhelm him. I think just the conversion to std::shared_ptr will be a good start. I just didn't want to scare @olzhas away. Stripping out stdlib pointers is a considerable undertaking, so I wanted to limit the scope. RE: CObject I think it's cleaner to have each class typedef their own smart pointer, but I think it would break a lot of what CObject currently does. For example:
|
Didn't know std:: variant, cool! Will see it's supported compilers, Just a note on your last proposal for typedefs: I'm on the phone now and We'll see... |
I think variants are a late add to the c++17 standard. Work in gcc only started a little over a month ago. I have to admit that I still struggle with those DEFINE_OBJECT macros. I find them very confusing. The nice thing about std::variants is that it that a single collection of variants can store very disparate types without requiring inheritance. It which helps preserve the sanity of your inheritance structure. Also, the visitor pattern is almost like pattern matching from haskell. |
@jolting got it. |
@olzhas This is what I had in mind with the variant: I still need to tackle the type info thing and refactoring a couple of places where CLASS_ID is checked which could be simplified using templates(i.e. CPoseRandomSampler). Take a look at CSerializable.h that uses the boost::variant for now. It should be trivial to replace this with std::variant. Notable take a look at libs/base/include/mrpt/utils/CStream.h. It has a templated operator >> and operator << which should make conversion to and from CSerializableOption. boost::get should throw an exception if the types don't match, which can easily be caught and rethrown into a reasonable exception message. Now each class just has a readStream, writeStream which can be called with a templated method for each observation type instead of using polymorphism, which seems like it's overkill for an interface. |
Hi @jolting ! wow, a lot of critical changes there :-) But, on the other side, the
What do you think?? |
I think the variant type doesn't suit the problem exactly, but I think it's a step in the right direction. Perhaps the solution is to create our own type by leveraging some C++11 features.
In c++11 we can use type indexes and create a hash lookup for the type name.
It seems that there is already partially a problem with this. Actually what we really need is std::any(forgive me for throwing another c++17 feature in there) |
Forgive the prototype nature of the code, but Perhaps something like this: |
I may have lost something, but I think that the only missing critical feature of this approach (without the ugly old macros) is the lack of a class factory, required for reading from rawlogs, etc. right? Do you think it's possible to do it somehow without relying on a central class registry, etc. etc. as it's done right now? |
I think so, but I'll have to mull it over before trying some more brutal refactoring tricks. I believe the context in which the rawlog is read really decides what types observations really need to be in the registry. You shouldn't need code to de-serialize an object you never intent to use(I think). Maybe the registry can just be local for the types that you want to read.
|
Just to keep this thread alive: during these months I've been updating the checklist at the top with related tasks. I hope we soon will have time to finally release 1.5.0 and put hands on 2.0.0! The only change I'm still reluctant to undertake is a replacement based on |
I don't think it would be useful to check that every class to be movable universally. The PDF variants of the poses definitely have the most to gain from move semantics and I think that is already covered. That particular item can be checked off the list. |
FYI: Today I finally removed the branch |
Update: 98aaaed removes our home-made |
Change function pointers to C++11 std::function<> wherever it makes sense. cc: #66
Point "CMake export" moved to a new issue #602 . It actually has nothing to do with C++ versions. |
Done with "Add constexpr to geometry constructors, etc." |
Done (mostly) with
|
Just deleted this one from the list, since it didn't have actually anything to do with C++14.
Also, I'm unsure about it usefulness right now... |
typedefs -> using (progress with #66)
I think the weak_ptr/shared_ptr muddies the interface a little all to avoids the somewhat trivial copy. You could pass it in as a parameter as well. That should avoid the copy as well.
|
I also had doubts about whether it's worth. Anyway, there should be no need for signature changes, unless I misunderstood you, since we already have |
On this one (almost the last one that remains in this ticket!):
I remember is what a @bergercookie 's thing related to traits of poses, but I don't know if that code is still around and where it is, etc. Any update on that part? I'll be happy of refactoring it, but just wanted to be sure it's still needed ;-) |
I'm marking this one as done after reviewing that the condition is fulfilled for "lightweight" and "regular" point and poses, and for matrices. |
Which type traits? |
That's the point... perhaps I'm making it up, but I could swear Nikos added some trait classes to the old mrpt-base module and we all agreed they could be refactored someday, but I just can't locate them now :-) |
On the mysterious missing "traits", I'll just mark it as done and if @bergercookie thinks it's something still in the to-do list, it could be added to #697. So, after almost 4 years, I think we can consider this task list as done... yay!! 🎉 |
Thanks, that one was on my radar, but it is fine as is: it defines graphslam-specific traits. The one I recall was related to poses and my thoughts then were that it seemed easily merge-able with |
To be done (in 2017? -> yes) when it's safe to assume everyone has a decent C++14 compiler.
This implies:
set (CMAKE_CXX_STANDARD 11)
, etc.std::thread
, unless there are strong reasons not to do so.<functional>
EXPORT
, etc.override
auto_ptr<>
#if MRPT_HAS_CXX11
mrpt::synch::CAtomicCounter
in favor of C++11std::atomic
.nullptr
MRPT_NO_THROWS
==> C++11.noexcept
uint32_t
enums with correct C++11 typed enums. E.g. inGNSS_BINARY_MSG_DEFINITION_START
mrpt::utils::delete_safe
and consider changing them to use C++11 smart pointers.typedef
s ==>using
constexpr
to geometry constructors, etc.alignas
instead of Eigen align macrosint a { 0 };
orint a = 0;
copy_ptr<>
, etc. with simpleusing ...
partial template specializations.using FP=...
to define functors.template<> using ...
instead of current aligned STL containers. ==> Nope: it would break existing code, it's not worth (Nov 3, 2017)std::vector
of fixed length withstd::array
. E.g. ReactiveNav classes, etc.noexcept
. Otherwise, they will not be eligible for "real move".weak_ptr
form_frame_tf
API in ReactiveNavMinimum compilers (see this table)
Minimum CMake version: 3.1
The text was updated successfully, but these errors were encountered: