Giter Club home page Giter Club logo

Comments (5)

anders-sjogren avatar anders-sjogren commented on May 31, 2024

I've implemented the analogue to this, but for another function than begin and with a few more options for customization (e.g. static member functions), but lacking the array case in section 6.5.4.1.1 of N4296. Is the priority tag idiom used below a good way to get the fallback mechanism of 6.5.4.1?

constexpr int MaxPrioLevel = 2;
template<int Level> struct Prio : public Prio<Level-1>
{
  constexpr Prio(){}
  static_assert(Level<=MaxPrioLevel,"Level must not be greater than MaxPrioLevel, to make sure MaxPrio means maximum priority. It is safe to increase MaxPrioLevel if needed.");
};
template<> struct Prio<0>{constexpr Prio(){}};
constexpr Prio<MaxPrioLevel> maxPrio;

struct begin_fn
{
private:
  //Array. Case 6.5.4.1.3 of N4296
  //TODO with Prio<2>

  //Member function. Case 6.5.4.1.2 of N4296
  template<typename T, typename... Args>
  auto f(Prio<1>, T&& x, Args&&... args) const ->
  decltype(std::forward<T>(x).begin(std::forward<Args>(args)...))
  {
    return std::forward<T>(x).begin(std::forward<Args>(args)...);
  }

  //Free function (e.g. from argument dependent lookup (ADL)). Case 6.5.4.1.3 of N4296
  template<typename... Args>
  auto f(Prio<0>, Args&&... args) const ->
  decltype(begin(std::forward<Args>(args)...))
  {
    return begin(std::forward<Args>(args)...);
  }
public:
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const
  {
    return this->f(maxPrio, std::forward<Args>(args)...);
  }
};

from range-v3.

anders-sjogren avatar anders-sjogren commented on May 31, 2024

Should all involved functions be constexpr?
If I understand 7.1.5.6 of N4296 correctly, it is valid to mark functions and member functions as constexpr even if for some template arguments they will not be constexpr? Will they in essence then be constexpr whenever the template arguments allow it then?
Should one always mark forwarding template functions constexpr?

from range-v3.

ericniebler avatar ericniebler commented on May 31, 2024

Your Prio class could be a handy way to implement this, but the partial ordering could be tricky once you add the array case.

from range-v3.

anders-sjogren avatar anders-sjogren commented on May 31, 2024

Could you elaborate on this?
If the array case is implemented with Prio<2>, it will be matched first for arrays, then member functions (as Prio<1>) and finally free functions (adl, as Prio<0>). Wouldn't this perfectly mimic 6.5.4.1?

from range-v3.

ericniebler avatar ericniebler commented on May 31, 2024

Fixed in e8332a5

from range-v3.

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.