Cant understand cpp snippet

0 votes

This snippet is lifted from bitcoin code base.

struct CombinerAll
{
    typedef bool result_type;

    template<typename I>
    bool operator()(I first, I last) const
    {
        while (first != last) {
            if (!(*first)) return false;
            ++first;
        }
        return true;
    }
};

This gets used here

boost::signals2::signal<bool (CNode*), CombinerAll> ProcessMessages;

I dont understand what it is for. Need help

Aug 27, 2018 in Blockchain by digger
• 26,740 points
471 views

1 answer to this question.

0 votes

From the function:

        if (!(*first)) return false;

If any of the elements in the range [first, last) evaluate to false when the pointer/iterator/object is dereferenced, the function returns false. Otherwise, it returns true.

Example test code:

int main()
{
   std::string sa = "abc";

   std::vector<int> va = {1, 1, 1};
   std::vector<int> vb = {1, 0, 2};

   std::cout << std::boolalpha;
   std::cout << CombinerAll()(sa.begin(), sa.end()) << std::endl;

   std::cout << CombinerAll()(va.begin(), va.end()) << std::endl;
   std::cout << CombinerAll()(vb.begin(), vb.end()) << std::endl;

   return 0;
}

Output:

true
true
false
answered Aug 27, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

+2 votes
1 answer

Blockchain declining my API key and I cannot understand why.

It's quite easy. Request the API key using ...READ MORE

answered Apr 3, 2018 in Blockchain by Christine
• 15,790 points
2,076 views
0 votes
1 answer

Can't import "blockchain.info" to Node.js.. Need help.

Aurelia is a client-side framework and blockchain ...READ MORE

answered Jun 27, 2018 in Blockchain by Omkar
• 69,220 points
1,069 views
0 votes
1 answer

Can't install remote HTTP chaincode

Fabric 1.0 does not support remote paths ...READ MORE

answered Jun 27, 2018 in Blockchain by Omkar
• 69,220 points
883 views
0 votes
1 answer

IBM Blockchain cant retrieving multiple rows from table

You can not use the older implementation ...READ MORE

answered Jul 5, 2018 in Blockchain by digger
• 26,740 points
671 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,459 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,942 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,468 views
0 votes
1 answer

Cant decode hex sting into decimal. Getting TypeError.

On the line where it shows error, ...READ MORE

answered Jul 6, 2018 in Blockchain by slayer
• 29,370 points
4,829 views
0 votes
1 answer

Can’t find value for key while using CouchDB for Fabric.

In the output you have mentioned: {   "id": ...READ MORE

answered Jul 31, 2018 in Blockchain by slayer
• 29,370 points
1,747 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP