0

I have a std::vector of std::tuples which store integral types along with a class which has no copy constructor. My aim is to add values to this vector without making any unnecessary copies of MyClass in the memory. Because, MyClass is going to store huge amount of data in my real application.

What I tried is:

#include <vector>
#include <tuple>
#include <iostream>
#include <string>

class MyClass
{
    public:
        MyClass()                   = delete;
        MyClass(const MyClass &)    = delete;
        MyClass(const std::wstring & str, float flt)
            : Text(str), Value(flt)
        {
        }

        std::wstring Text;
        float Value;

    private:
};

int wmain(int argc, wchar_t *argv[], wchar_t *envp[])
{
    std::vector<std::tuple<MyClass, int, double>> Items;
    Items.emplace_back(L"Entry0", 2.3f, 5, 5.7);
    Items.emplace_back(L"Entry1", 3.4f, 6, 6.8);
    Items.emplace_back(L"Entry2", 4.5f, 7, 7.9);
    for (size_t i=0; i<Items.size(); i++)
    {
        std::wcout << std::get<0>(Items[i]).Text    << L'\t';
        std::wcout << std::get<0>(Items[i]).Value   << L'\t';
        std::wcout << std::get<1>(Items[i])         << L'\t';
        std::wcout << std::get<2>(Items[i])         << std::endl;
    }

    _wsystem(L"pause");
    return 0;
}

Visual Studio 2015 gives the following error somewhere inside the standard library file "xmemory0".

'std::tuple::tuple(std::tuple &&)': cannot convert argument 1 from 'const wchar_t [7]' to 'std::_Tuple_alloc_t'
xmemory0 657

What is the correct way of doing this?

hkBattousai
  • 10,583
  • 18
  • 76
  • 124

0 Answers0