Giter Site home page Giter Site logo

Incorrect use of move about apecs HOT 3 CLOSED

ColinH avatar ColinH commented on May 31, 2024
Incorrect use of move

from apecs.

Comments (3)

ColinH avatar ColinH commented on May 31, 2024 1

it would have been handled by the registry<Comps...>::add(apx::entity entity, const Comp& component) overload?

Unfortunately (?) not, it chooses the other overload. It can be slightly annoying because the overload resolution between const foo& and foo&& behaves differently depending on whether foo is a template parameter or not, so one also has to be extra careful when refactoring code and transforming back or forth between a function and a function template...

colin@magic:/tmp/ramdisk> cat t.cpp 
#include <string>
#include <iostream>

struct foo
{
   template< typename T >
   int bar( T&& )
   {
      std::cerr << "+++" << std::endl;
      std::cerr << __PRETTY_FUNCTION__ << std::endl;
      return 1;
   }

   template< typename T >
   int bar( const T& )
   {
      std::cerr << "---" << std::endl;
      std::cerr << __PRETTY_FUNCTION__ << std::endl;
      return 2;
   }
};

int main()
{
   foo f;
   std::string a;
   const std::string b;
   return f.bar( a ) + f.bar( std::move( a ) ) + f.bar( b );
}
colin@magic:/tmp/ramdisk> clang++ -Wall -Wextra -O3 -pedantic -std=c++17 t.cpp 
colin@magic:/tmp/ramdisk> ./a.out 
+++
int foo::bar(T &&) [T = std::__1::basic_string<char> &]
+++
int foo::bar(T &&) [T = std::__1::basic_string<char>]
---
int foo::bar(const T &) [T = std::__1::basic_string<char>]

from apecs.

fullptr avatar fullptr commented on May 31, 2024

I suspect I may have gotten away with this, since if I passed a some_component_type& it would have been handled by the registry<Comps...>::add(apx::entity entity, const Comp& component) overload? Nevertheless this is a very nice simplification.

from apecs.

fullptr avatar fullptr commented on May 31, 2024

Ahh I see, that example makes it very clear, thanks!

from apecs.

Related Issues (4)

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.