1

I use the boost::serialization library. When compiling i get a lot of lengthy warnings which seem to be related to not using file_version in the serialize function. (compiler: g++)

Is there a smart way to disable those warnings for those functions explicitly, as i like unused variable warnings in general which help avoiding stupid mistakes.

code example (very much not self contained, but should suffice to make a point):

template<class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
    ar & this->bias_;
    for(auto& layer : this->layers_)
        ar & layer; // old boost version doesn't do this for containers.
}

my idea of just writing

template<class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
    file_version;
    ar & this->bias_;
    for(auto& layer : this->layers_)
        ar & layer;
}

rightfully brings up another warning.

Gladaed
  • 211
  • 1
  • 8
  • w.r.t. the funny comments http://www.boost.org/doc/libs/1_66_0/libs/serialization/doc/serialization.html#constructors – sehe Mar 21 '18 at 14:33
  • @sehe i can't see funny comments in there. Can you explain the joke? did you link the wrong section? i don't get what you are saying. – Gladaed Mar 21 '18 at 14:39
  • _"`// boost bug - can't handle non copy constructability`"_ - that's not a boost bug, see the link (also, [funny](https://www.merriam-webster.com/dictionary/funny) ad. 2) – sehe Mar 21 '18 at 14:40
  • @sehe the comment is there since boost did not allow me to write ar & this->layers_ (if i googled correctly fixed in 1.6.1) – Gladaed Mar 21 '18 at 14:43
  • 1.6.1? That's not a version I remember seeing. And it's likely just including a certain header, though of course I can't know what the type of `layers_` is (inb4 [`hash_map`](https://stackoverflow.com/questions/23764249/c-boost-serialization-error-for-hash-map-with-custom-objects-as-key/23768271#23768271) ). Note though, with the loop it will only ever work if `layers_` is a fixed size container. – sehe Mar 21 '18 at 14:46
  • std::vector. i think i meant 1_61 aswell. – Gladaed Mar 21 '18 at 14:47
  • That always worked. (`#include `). [The changelog](http://www.boost.org/doc/libs/1_66_0/libs/serialization/doc/release.html) doesn't indicate changes since 1.58.0. I'll assume you had a really issue with it, just know the current code is invalid unless the vector has a fixed size. – sehe Mar 21 '18 at 14:50
  • @sehe thank you that was it. this manual way works if i don't change the size of the vector, even if i didn't fix it manually. – Gladaed Mar 21 '18 at 15:48
  • The crucial thing is that the size (number of elements) is assumed to be "correct" for the serialized data when deserializing. This, in practice, means that the size needs to be fixed. – sehe Mar 21 '18 at 16:23
  • @sehe by the way can i safely throw exceptions while deserializing data (eg. if i saved the old size and found a mismatch) – Gladaed Mar 21 '18 at 16:34
  • Yes, though you'd naturally use the version parameter to detect/handle that! http://www.boost.org/doc/libs/1_66_0/libs/serialization/example/demo_exception.cpp – sehe Mar 21 '18 at 16:46

1 Answers1

4

You can just declare the argument anonymously:

template<class Archive>
void serialize(Archive &ar, const unsigned int /*file_version*/)
{
    ar & this->bias_;
    for(auto& layer : this->layers_)
        ar & layer; // old boost version doesn't do this for containers.
}
sehe
  • 374,641
  • 47
  • 450
  • 633