error: no viable conversion from 'tuple<[...], std::__1::tuple<unsigned long long, unsigned long long>>' to 'const tuple<[...], uint_type>'

Suhaib

I'm trying to implement Ackerman function using a tuple of unsinged long long

This is the line that i'm trying to create

A(m, n) = A(m - 1, A(m, n - 1))

So here is my code:

    uint_type calculate(tuple_type const& args) const {

    uint_type retval;

        uint_type retval;

        auto second = make_tuple(m - 1, calculate(make_tuple(m, n - 1)));
        auto first = make_tuple(m - 1, second);
        retval = calculate(first);
        return retval;
       }
   };

and here is the error:

error: no viable conversion from 'tuple<[...], std::__1::tuple>' to 'const tuple<[...], uint_type>' retval = calculate(firstTuple);

^~~~~~~~~~emphasized text

Dietrich Epp

Type errors are sometimes hard to find if you use a lot of auto and template functions like make_tuple. Here's how you'd write it with less use of auto and make_tuple:

uint_type calculate(tuple_type const& args) const {
    const uint_type m = get<0>(args);
    const uint_type n = get<1>(args);

    uint_type retval;

    tuple_type second{m - 1, calculate(tuple_type{m, n - 1})};
    tuple_type first{m - 1, second};
    //                      ^^^^^^ error
    retval = calculate(first);
    return retval;
}

You can see how adding a couple type annotations moved the error message exactly to where the error is.

However, that's not the Ackermann function. This is the Ackermann function:

uint_type calculate(tuple_type args) const {
    const uint_type m = get<0>(args);
    const uint_type n = get<1>(args);
    if (m == 0)
        return n + 1;
    if (n == 0)
        return calculate(tuple_type{m - 1, 1});
    return calculate(tuple_type{m - 1, calculate(tuple_type{m, n - 1})});
}

Note that the tuple_type can be omitted:

uint_type calculate(tuple_type args) const {
    const uint_type m = get<0>(args);
    const uint_type n = get<1>(args);
    if (m == 0)
        return n + 1;
    if (n == 0)
        return calculate({m - 1, 1});
    return calculate({m - 1, calculate({m, n - 1})});
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Conversion issue of long long to unsigned long

From Dev

Unsigned long long overflow error?

From Dev

Idiom for long tuple unpacking

From Dev

converting from unsigned long long to unsigned int

From Dev

Conversion of unsigned long to std::vector with memcpy, endian?

From Dev

Issues with unsigned long long

From Dev

Unsigned long long overflow

From Dev

Is conversion int -> unsigned long long defined by the standard

From Dev

Is std::streampos guaranteed to be unsigned long long?

From Dev

Type conversion: signed int to unsigned long in C

From Java

N long tuple as optional argument

From Dev

Avoid long tuple definitions in haskell

From Dev

Unsigned Long Long from Double in Swift

From Dev

Qt : from unsigned long long to QJsonObject

From Dev

unsigned long long type printing in hexadecimal format

From Dev

error: invalid conversion from 'DWORD {aka long unsigned int}' to 'PDWORD {aka long unsigned int*}' [-fpermissive]| how to fix?

From Dev

C unsigned long long and imulq

From Dev

Check if unsigned long long is available

From Dev

Larger than Unsigned Long Long

From Dev

Larger than Unsigned Long Long

From Dev

What does (unsigned long)1 and *(unsigned long *) mean?

From Dev

Undefined reference to crcsum(unsigned char const*, unsigned long, unsigned short)

From Dev

Implicit conversion loses integer precision: 'unsigned long' to 'int' - Error

From Dev

"error: no viable conversion from tuple..." using make_tuple

From Dev

Converting Const char * to Unsigned long int - strtoul

From Dev

implicit conversion of 'unsigned long 'UIUserNotificationSettings *' is disallowed with arc

From Dev

implicit conversion of 'unsigned long 'UIUserNotificationSettings *' is disallowed with arc

From Dev

Unsigned long into char array

From Dev

Cant solve "warning: conversion to 'long unsigned int' from 'int'"

Related Related

  1. 1

    Conversion issue of long long to unsigned long

  2. 2

    Unsigned long long overflow error?

  3. 3

    Idiom for long tuple unpacking

  4. 4

    converting from unsigned long long to unsigned int

  5. 5

    Conversion of unsigned long to std::vector with memcpy, endian?

  6. 6

    Issues with unsigned long long

  7. 7

    Unsigned long long overflow

  8. 8

    Is conversion int -> unsigned long long defined by the standard

  9. 9

    Is std::streampos guaranteed to be unsigned long long?

  10. 10

    Type conversion: signed int to unsigned long in C

  11. 11

    N long tuple as optional argument

  12. 12

    Avoid long tuple definitions in haskell

  13. 13

    Unsigned Long Long from Double in Swift

  14. 14

    Qt : from unsigned long long to QJsonObject

  15. 15

    unsigned long long type printing in hexadecimal format

  16. 16

    error: invalid conversion from 'DWORD {aka long unsigned int}' to 'PDWORD {aka long unsigned int*}' [-fpermissive]| how to fix?

  17. 17

    C unsigned long long and imulq

  18. 18

    Check if unsigned long long is available

  19. 19

    Larger than Unsigned Long Long

  20. 20

    Larger than Unsigned Long Long

  21. 21

    What does (unsigned long)1 and *(unsigned long *) mean?

  22. 22

    Undefined reference to crcsum(unsigned char const*, unsigned long, unsigned short)

  23. 23

    Implicit conversion loses integer precision: 'unsigned long' to 'int' - Error

  24. 24

    "error: no viable conversion from tuple..." using make_tuple

  25. 25

    Converting Const char * to Unsigned long int - strtoul

  26. 26

    implicit conversion of 'unsigned long 'UIUserNotificationSettings *' is disallowed with arc

  27. 27

    implicit conversion of 'unsigned long 'UIUserNotificationSettings *' is disallowed with arc

  28. 28

    Unsigned long into char array

  29. 29

    Cant solve "warning: conversion to 'long unsigned int' from 'int'"

HotTag

Archive