Giter VIP home page Giter VIP logo

Comments (10)

GiulioRomualdi avatar GiulioRomualdi commented on June 19, 2024 1

with this

std::vector<int32_t> v{2};
matioCpp::Span<int32_t> s{v};

everything works fine

It is nice to have this deduction guide since it will allow to write the following code

void foo(Span<int> s);

std::vector<int> v{1};
foo(v);

right now what we should do is

void foo(Span<int> s);

std::vector<int> v{1};
foo(make_span(v));

Notice that make_span is not defined by the standard

from matio-cpp.

S-Dafarra avatar S-Dafarra commented on June 19, 2024 1
std::ranges::range_reference_t

Ah I see. The problem is that std::ranges is C++20 (https://en.cppreference.com/w/cpp/ranges)

from matio-cpp.

S-Dafarra avatar S-Dafarra commented on June 19, 2024 1

I would say that before moving to a completely new implementation, I would like to understand if it is possible to fix the current implementation.

Moving to a new implementation of span might be potentially a lot of work (also for those applications depending on this). I would rather do this step only once, when std::span will be more accessible

from matio-cpp.

S-Dafarra avatar S-Dafarra commented on June 19, 2024

Yes, the relevant error is

In file included from /home/gromualdi/robot-code/yarp-telemetry/src/libYARP_telemetry/src/yarp/telemetry/experimental/Record.h:12,
                 from /home/gromualdi/robot-code/yarp-telemetry/src/examples/circular_buffer_record_example.cpp:14:
/home/gromualdi/robot-code/robotology-superbuild/build/install/include/matioCpp/Span.h:411:24: note: candidate: ā€˜template<class ElementType, long int Extent, class Container, class, class> Span(const Container&)-> matioCpp::Span<ElementType, Extent>ā€™
  411 |     MATIOCPP_CONSTEXPR Span(const Container& cont) : Span(cont.data(), static_cast<index_type>(cont.size()))
      |                        ^~~~
/home/gromualdi/robot-code/robotology-superbuild/build/install/include/matioCpp/Span.h:411:24: note:   template argument deduction/substitution failed:
/home/gromualdi/robot-code/yarp-telemetry/src/examples/circular_buffer_record_example.cpp:44:27: note:   couldnā€™t deduce template parameter ā€˜ElementTypeā€™
   44 |         matioCpp::Span s{v};
      |                           ^
In file included from /home/gromualdi/robot-code/yarp-telemetry/src/libYARP_telemetry/src/yarp/telemetry/experimental/Record.h:12,
                 from /home/gromualdi/robot-code/yarp-telemetry/src/examples/circular_buffer_record_example.cpp:14:
/home/gromualdi/robot-code/robotology-superbuild/build/install/include/matioCpp/Span.h:402:24: note: candidate: ā€˜template<class ElementType, long int Extent, class Container, class, class> Span(Container&)-> matioCpp::Span<ElementType, Extent>ā€™
  402 |     MATIOCPP_CONSTEXPR Span(Container& cont) : Span(cont.data(), static_cast<index_type>(cont.size()))
      |                        ^~~~
/home/gromualdi/robot-code/robotology-superbuild/build/install/include/matioCpp/Span.h:402:24: note:   template argument deduction/substitution failed:
/home/gromualdi/robot-code/yarp-telemetry/src/examples/circular_buffer_record_example.cpp:44:27: note:   couldnā€™t deduce template parameter ā€˜ElementTypeā€™

As you noticed, it fails to deduce the ElementType.

I am not sure I understood what you meant in

In this case the used deduction guides used should be:

template<class R>
span(R&&) -> span<std::remove_reference_t<std::ranges::range_reference_t<R>>>;

from matio-cpp.

GiulioRomualdi avatar GiulioRomualdi commented on June 19, 2024

I am not sure I understood what you meant in

In this case the used deduction guides used should be:

template<class R>
span(R&&) -> span<std::remove_reference_t<std::ranges::range_reference_t<R>>>;

Accordingly to what is written here
the deduction guide used for std::vector is
image

image

from matio-cpp.

GiulioRomualdi avatar GiulioRomualdi commented on June 19, 2024

This implementation seems able to perform the deduction. https://github.com/martinmoene/span-lite

What do you think to port it matio-cpp?

from matio-cpp.

GiulioRomualdi avatar GiulioRomualdi commented on June 19, 2024

Before taking any decision let me try in a toy problem šŸ˜ƒ

from matio-cpp.

GiulioRomualdi avatar GiulioRomualdi commented on June 19, 2024

The following code works with span-line

#include "nonstd/span.hpp"
#include <array>
#include <vector>
#include <iostream>

std::ptrdiff_t size( nonstd::span<const int> spn )
{
    return spn.size();
}

int main()
{
    int arr[] = { 1, };

    std::cout <<
        "C-array:" << size( arr ) <<
        " array:"  << size( std::array <int, 2>{ 1, 2, } ) <<
        " vector:" << size( std::vector<int   >{ 1, 2, 3, } );
}

from matio-cpp.

S-Dafarra avatar S-Dafarra commented on June 19, 2024

I tried to edit the SpanUnitTest as follows
image

But I am able to compile šŸ¤”

from matio-cpp.

S-Dafarra avatar S-Dafarra commented on June 19, 2024

See 708827b

from matio-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.