473,785 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Diggins PDP #2 : Meta-Binders (binding functions to functions)

// meta_binder.hpp
// The Diggins PDP (Public Domain Post) #2
// Public Domain code by Christopher Diggins, May 22, 2005
//
// Description:
// A meta-binder binds function objects to function objects
//
// Motivation:
// lack of a logical_xor in the standard library, and no way to construct
one using the
// standard library using binders and adapters.

#ifndef META_BINDER_HPP
#define META_BINDER_HPP

#include <stdexcept>
#include <functional>

namespace cdiggins
{
template<class BinOp, class BinOpArg1, class BinOpArg2>
class meta_binder2 : public std::binary_fun ction
<
typename BinOp::first_ar gument_type,
typename BinOp::second_a rgument_type,
typename BinOp::result_t ype

{
protected:
BinOp op;
BinOpArg1 arg1;
BinOpArg2 arg2;
public:
meta_binder2(Bi nOp x, BinOpArg1 a1, BinOpArg2 a2) : op(x), arg1(a1),
arg2(a2)
{ }
typename BinOp::result_t ype operator()
(const typename BinOp::first_ar gument_type& x,
const typename BinOp::second_a rgument_type& y)
{
return op(arg1(x, y), arg2(x, y));
}
};

template<class BinOp, class BinOpArg1, class BinOpArg2>
meta_binder2<Bi nOp, BinOpArg1, BinOpArg2>
meta_bind2(BinO p op, BinOpArg1 arg1, BinOpArg2 arg2) {
return meta_binder2<Bi nOp, BinOpArg1, BinOpArg2>(op, arg1, arg2);
}
}

void test(bool b) {
if (!b)
throw std::runtime_er ror("test failed");
}

namespace meta_binder_tes t
{
using namespace cdiggins;

bool logical_xor(boo l x, bool y) {
return (x || y) && !(x && y);
}

void xor_test(bool x, bool y) {
test(logical_xo r(x, y) ==
meta_bind2(
std::logical_an d<bool>(),
std::logical_or <bool>(),
std::not2(std:: logical_and<boo l>())
)(x, y));
}

void test_main()
{
xor_test(true, true);
xor_test(true, false);
xor_test(false, true);
xor_test(false, false);
}
}

#endif

--
Christopher Diggins
http://www.cdiggins.com
Jul 23 '05 #1
1 1384
christopher diggins wrote:
// meta_binder.hpp
// The Diggins PDP (Public Domain Post) #2
// Public Domain code by Christopher Diggins, May 22, 2005
//
// Description:
// A meta-binder binds function objects to function objects
//
// Motivation:
// lack of a logical_xor in the standard library, and no way to construct one using the
// standard library using binders and adapters.


Did it ever occur to you that normal C++ programmers may be reluctant
to write something like:

logical_xor(x, y) ==
meta_bind2(
std::logical_an d<bool>(),
std::logical_or <bool>(),
std::not2(std:: logical_and<boo *l>())
)(x, y);
?

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4015
by: Cezary | last post by:
Hello. I was read PHP manual, but i'm not sure yet. Here is my meta tags in html: <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-2"> <META HTTP-EQUIV="Expires" CONTENT="0"> <META HTTP-EQUIV="Cache-Control" CONTENT="no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
4
3725
by: Brian | last post by:
Hi, I'm trying to use standard meta tags in an xsl doc and using cocoon as my processor. The problem is that cocoon changes for example: <meta name="keywords" content="test, test, test" /> to <meta content="test, test, test" name="keywords"> I hope that makes sense. The problem is that I am running some adds on my
19
3861
by: Christian Hvid | last post by:
Hello groups. I have a series of applet computer games on my homepage: http://vredungmand.dk/games/erik-spillet/index.html http://vredungmand.dk/games/nohats/index.html http://vredungmand.dk/games/platfoot/index.html http://vredungmand.dk/games/minorbug/index.html http://vredungmand.dk/games/timbuktu/index.html http://vredungmand.dk/games/taleban/index.html
24
3553
by: Day Bird Loft | last post by:
Web Authoring | Meta-Tags The first thing to understand in regard to Meta Tags is the three most important tags placed in the head of your html documents. They are the title, description, and keyword meta-tags. If you are missing any of these meta-tags you are missing the boat. If you use the following meta-tag formula, and you are not trying to deceive the spiders, I guarantee you will succeed in increasing your placement in the...
4
2740
by: christopher diggins | last post by:
Welcome to the first installment of the Diggins Public Domain Posts (PDP). There is a significant dearth of good public domain C++ code. All of it seems to come with one kind of a license or another, and even though I understand the motivations, I believe code is like mathematics and no one can really own it. Rather than stand on a pulpit, or debate the philosophical merits of the various licenses, I have decided instead to post as much...
0
2510
by: christopher diggins | last post by:
// binary_aritmetic.hpp // Diggins PDP (Public Domain Post) #1.2 // by Christopher Diggins, May 24, 2005 // // Comment: // Provides several algorithms for unsigned binary arithmetic // // Changes: // Now includes a full_subtractor
0
1984
by: christopher diggins | last post by:
// The Diggins PDP (Public Domain Post) #4 // public domain code for computing the FFT // contributed by Christopher Diggins, 2005 template<int N> unsigned int bit_reverse(unsigned int x) { int n = 0; int mask = 0x1; for (int i=0; i < N; i++) { n <<= 1;
3
32907
by: J1C | last post by:
How can I programatically add meta tags with javascript?
5
12098
by: RodneyDunes | last post by:
My site did validate and now it doesn't. The error I get is the following: document type does not allow element "META" here ....nt-type" content="text/html;charset=iso-8859-1"> Can someone please tell me what I need to change?These are the Meta tags: </head> <meta http-equiv="Content-type" content="text/html;charset=iso-8859-1"> <META http-equiv="PICS-Label" content=(PICS-1.1 "http://www.classify.org/safesurf/" L gen true for
1
1958
by: Maziar Aflatoun | last post by:
Hi everyone, My goal is to modify the contents of my meta tag (html refresh). However, my code adds a new instance of the meta tag at the bottom of the page. Is there a way to modify it instead of adding a new one? <head> <title>WebForm1</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#">
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.