no matching function for call to std::vector<std::tuple> push_back

Abhinav Gauniyal

I have a sample program containing 6 timepoints using high_resolution_clock::now() from standard chrono header. I take differences b/w each of them resulting in 3 differences and caste them as auto duration1 = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); to microseconds.

I have another variable named durations which is assigned as follows: auto durations = std::make_tuple(duration1,duration2,duration3); containing previous time-point differences.

I have to push this tuple into an vector, so I have introduced std::vector<std::tuple<std::chrono::microseconds,std::chrono::microseconds,std::chrono::microseconds>> list; However on using list.push_back(durations); I get an error as :

prog.cpp: In function 'int main()':
prog.cpp:36:29: error: no matching function for call to 'std::vector<std::tuple<std::chrono::duration<long long int, std::ratio<1ll, 1000000ll> >, std::chrono::duration<long long int, std::ratio<1ll, 1000000ll> >, std::chrono::duration<long long int, std::ratio<1ll, 1000000ll> > > >::push_back(std::tuple<long long int, long long int, long long int>&)'
     list.push_back(durations);

I tried to search about std::chrono::microseconds and other std::chrono::duration stuff here but wasn't successful in rectifying the problem.

I know this has something to do with my negligence of type system, but I'm unable to locate that error. Any help would be appreciated, & here is ideone link.

#include <iostream>
#include <chrono>
#include <vector>
#include <tuple>

using namespace std;
using namespace std::chrono;

void function()
{
    long long number = 0;

    for( long long i = 0; i != 2000000; ++i )
    {
       number += 5;
    }
}

int main()
{
    high_resolution_clock::time_point t1 = high_resolution_clock::now();
    high_resolution_clock::time_point t3 = high_resolution_clock::now();
    high_resolution_clock::time_point t5 = high_resolution_clock::now();
    function();
    high_resolution_clock::time_point t2 = high_resolution_clock::now();
    high_resolution_clock::time_point t4 = high_resolution_clock::now();
    high_resolution_clock::time_point t6 = high_resolution_clock::now();

    auto duration1 = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
    auto duration2 = std::chrono::duration_cast<std::chrono::microseconds>( t4 - t3 ).count();
    auto duration3 = std::chrono::duration_cast<std::chrono::microseconds>( t6 - t5 ).count();

    auto durations = std::make_tuple(duration1,duration2,duration3);

    std::vector<std::tuple<std::chrono::microseconds,std::chrono::microseconds,std::chrono::microseconds>> list;
    list.push_back(durations);

    cout << duration1 << " -- "<< duration2 << " -- "<< duration3 << " -- ";
    return 0;
}
Jonathan Wakely

You have created a tuple of 3 integers and you're trying to add it to a vector of 3 durations.

I take differences b/w each of them resulting in 3 differences and caste them as auto duration1 = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); to microseconds.

Why are you calling count() on the durations after doing the duration_cast to convert to microseconds?

Just keep the values as microseconds objects and you can add them to the vector:

auto duration1 = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 );
auto duration2 = std::chrono::duration_cast<std::chrono::microseconds>( t4 - t3 );
auto duration3 = std::chrono::duration_cast<std::chrono::microseconds>( t6 - t5 );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

c++ no matching function for call to vector push_back

From Dev

Weird segment fault in function push_back of std::vector

From Dev

Passing std vector as reference: no matching function to call

From Java

Insert or push_back to end of a std::vector?

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

vector::push_back and std::move

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

Taking the argument by && in std::vector push_back() and std::map operator[]

From Dev

Fix error no matching function for call to 'assign' in std::vector<std::vector<UC> > lum;

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

Thread safety std::vector push_back and reserve

From Dev

Cost of std::vector::push_back either succeeding or having no effect?

From Dev

Why std::vector::push_back needs the assignment operator

From Dev

std::vector segmentation fault during push_back

From Dev

Thread safety std::vector push_back and reserve

From Dev

std::vector of OpenCV points, no push_back method

From Dev

Why std::vector::push_back segfaults with virtual destructor?

From Dev

Examples where std::vector::emplace_back is slower than std::vector::push_back?

From Dev

Call member function for each element of std::tuple

From Dev

vector memory allocation call to copy constructor with push_back function

From Dev

std::vector<std::vector<int>> push_back gives heap-buffer-overflow

From Dev

Callable class objects in C++ : no matching function for call to ‘std::tuple<T>::tuple(<brace-enclosed initializer list>)’

From Dev

No matching function for call to 'std::advance' error

From Dev

No matching function for call to 'std::advance' error

From Dev

Compilation error : "no matching function for call to ‘std::vector<Card*>::insert(int, Card*&)’" C++

From Dev

Is a std::unique_ptr moved into a std::vector when using push_back?

From Dev

std::string in object being deleted during push_back to std::vector

From Dev

std::vector<std::tuple in for - cannot get values

Related Related

  1. 1

    c++ no matching function for call to vector push_back

  2. 2

    Weird segment fault in function push_back of std::vector

  3. 3

    Passing std vector as reference: no matching function to call

  4. 4

    Insert or push_back to end of a std::vector?

  5. 5

    Implementatnion of std::vector::push_back in MSVC

  6. 6

    vector::push_back and std::move

  7. 7

    Implementatnion of std::vector::push_back in MSVC

  8. 8

    Taking the argument by && in std::vector push_back() and std::map operator[]

  9. 9

    Fix error no matching function for call to 'assign' in std::vector<std::vector<UC> > lum;

  10. 10

    Calling std::vector::push_back() is changing previous elements in vector?

  11. 11

    Calling std::vector::push_back() is changing previous elements in vector?

  12. 12

    Thread safety std::vector push_back and reserve

  13. 13

    Cost of std::vector::push_back either succeeding or having no effect?

  14. 14

    Why std::vector::push_back needs the assignment operator

  15. 15

    std::vector segmentation fault during push_back

  16. 16

    Thread safety std::vector push_back and reserve

  17. 17

    std::vector of OpenCV points, no push_back method

  18. 18

    Why std::vector::push_back segfaults with virtual destructor?

  19. 19

    Examples where std::vector::emplace_back is slower than std::vector::push_back?

  20. 20

    Call member function for each element of std::tuple

  21. 21

    vector memory allocation call to copy constructor with push_back function

  22. 22

    std::vector<std::vector<int>> push_back gives heap-buffer-overflow

  23. 23

    Callable class objects in C++ : no matching function for call to ‘std::tuple<T>::tuple(<brace-enclosed initializer list>)’

  24. 24

    No matching function for call to 'std::advance' error

  25. 25

    No matching function for call to 'std::advance' error

  26. 26

    Compilation error : "no matching function for call to ‘std::vector<Card*>::insert(int, Card*&)’" C++

  27. 27

    Is a std::unique_ptr moved into a std::vector when using push_back?

  28. 28

    std::string in object being deleted during push_back to std::vector

  29. 29

    std::vector<std::tuple in for - cannot get values

HotTag

Archive