Coder Social home page Coder Social logo

Comments (4)

rollbear avatar rollbear commented on August 16, 2024

It is not currently possible, no.

A possible work around is:

template <typename T>
auto needsUpdate(T&  t)
{
  return NAMED_REQUIRE_CALL(t, NeedAnyUpdates()).RETURN(true);
}

template <typename ... T>
auto theseNeedUpdates(T& ... t)
{
  std::vector<std::unique_ptr<trompeloeil::expectation>> rv;
  std::initializer_list<int>{(rv.push_back(needsUpdate(t)),0)...};
  return rv;
}

The initializer_list<int> thingie is an ugly work around for the lack of fold-expressions in C++14. It forces the calls to needsUpdate() for each t, and uses the comma operator to add a 0 to the initializer_list.

Then, in your test, you write:

  auto needsUpdates = theeseNeedsUpdates(m1, m2); // vector of expectations
  ... // things that may call NeedAnyUpdates()...

Is a smoother work solution very important for you? I do currently not have any idea how to implement it, so a smooth solution may take a while to get in place.

from trompeloeil.

rcdailey avatar rcdailey commented on August 16, 2024

That feels very over-engineered. I didn't mean to imply that initializer lists were required. I'd be fine with something like this (if it makes it cleaner):

auto& um = CUpdateManager::Instance();

std::vector<MockUpdateReceiver> receivers(2);

um.AddReceiver(&receivers[0]);
um.AddReceiver(&receivers[1]);

REQUIRE_CALL(receivers, NeedAnyUpdates()).RETURN(true);
REQUIRE_CALL(receivers, Update(0.f));

um.Update(0.f);

And internally you can have special overloads for std::vector<T> and just run a loop that forwards to the version taking a single mock (T)

from trompeloeil.

rollbear avatar rollbear commented on August 16, 2024

I agree, but currently the presented work-around is the best I can offer. I'll try to figure out a better way.

from trompeloeil.

rcdailey avatar rcdailey commented on August 16, 2024

I'll go ahead and close this one, it's a bit of an edge case and likely not going to be a good ROI. I haven't run into this too often myself, even.

from trompeloeil.

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.