私は、という2つのタイプの単一のメンバを持つクラスを持っています:vector
の整数と、それを含むクラスオブジェクトのvector
recursive_wrapper
の助けを借りて)。私はTestVariant
のvector
を作成し、TestVariantの再帰的なインスタンスのインスタンスを据え付けることにより、このクラスを使用しようとすると、私は「アクセスを取得boost :: variant:再帰的なベクトル型で異常な振る舞い
std::vector<TestVariant> v;
v.emplace_back(std::vector<TestVariant>{ std::vector<TestVariant>{}, std::vector<int>{} }); // access violation!
次のようにクラスのコードは
#include <boost/variant/variant.hpp>
#include <boost/variant/recursive_wrapper.hpp>
#include <vector>
class TestVariant
{
public:
typedef boost::variant< std::vector<int>, boost::recursive_wrapper<std::vector<TestVariant> > > StorageType;
TestVariant():
m_value{ std::vector<int>{} }
{}
TestVariant(const TestVariant& other):
m_value{ other.m_value }
{}
TestVariant& operator=(const TestVariant& other)
{
m_value = other.m_value;
return *this;
}
TestVariant(TestVariant&& other):
m_value{ std::move(other.m_value) }
{}
TestVariant& operator=(TestVariant&& other)
{
m_value = std::move(other.m_value);
return *this;
}
TestVariant(const std::vector<int>& value):
m_value{ value }
{}
TestVariant(std::vector<int>&& value):
m_value{ std::move(value) }
{}
TestVariant(const std::vector<TestVariant>& value):
m_value{ value }
{}
TestVariant(std::vector<TestVariant>&& value):
m_value{ std::move(value) }
{}
private:
StorageType m_value;
};
を下回っていますMSVS 2013とBoost ver 1.53の「違反」の例外(私はこれがBoostの古いバージョンであることを知っていますが、現時点ではこれを使用するように組織的に制約されています)。 coliruの同じコードがうまく動作します(here参照)。
何でも見知らぬ人であることは
std::vector<TestVariant> v;
v.emplace_back(std::vector<TestVariant>{std::vector<int>{}, std::vector<TestVariant>{} }); // works!
MSVS 2013年に、私は2つのベクトルの順序を切り替えた場合、すべてが正常であると考えられるということである任意のアイデア?私は今これを解決しようとしています...
それはwouldn MSVS2013または古いバージョンのバグがあることを見つけるのは珍しいことです。これはあなたの組織が正しいことをしてアップグレードするべきだと主張するよい機会かもしれません。 –
@RichardHodges私はもっと同意できませんでしたが、コグはゆっくり回り、その間に回避策が必要です... –
seheの解答ヘルプですか?私はそれを試してみたいと思うが、私のWindowsコンピュータにvs2015をインストールするには2日かかってしまったので、私は並行インストールを試していない。最近、Windows用のコードを記述する必要がある場合は、clangまたはCygwinを使用します。私はちょうどMicrosoftを信頼していない... –