Topic: Why aren't bitwise function objects in the standard?
Author: chandra.kumar@oracle.com (Chandra Shekhar Kumar)
Date: Tue, 24 Jun 2003 05:16:35 +0000 (UTC) Raw View
===================================== MODERATOR'S COMMENT:
Please don't overquote.
===================================== END OF MODERATOR'S COMMENT
ideally yes, it could have been in the standard.
but it's not a tedious work to implement it using the unary_function and
binary_function provided by the standard and for more hint , you can look
the header <bitset>
KIM Seungbeom wrote:
> I don't see why the bitwise function objects (namely bitwise_and,
> bitwise_or and bitwise_xor) are not in the standard. Is there any reason?
> Was it a mere mistake, as in the case of copy_if?
>
> Once in a project I had to implement those on my own, a tedious work.
> Probably they should be included in the next revision of the standard.
>
> --
> KIM Seungbeom <musiphil@bawi.org>
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: musiphil@bawi.org (KIM Seungbeom)
Date: Fri, 27 Jun 2003 17:55:13 +0000 (UTC) Raw View
chandra.kumar@oracle.com (Chandra Shekhar Kumar) wrote in message news:<3EF734DF.3318B5B8@oracle.com>...
> ideally yes, it could have been in the standard.
> but it's not a tedious work to implement it using the unary_function and
> binary_function provided by the standard and for more hint , you can look
> the header <bitset>
What does <bitset> have to do with bitwise operations?
I meant something like these:
template<typename T>
struct bitwise_and : std::binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x & y; }
};
template<typename T>
struct bitwise_or : std::binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x | y; }
};
template<typename T>
struct bitwise_xor : std::binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const { return x ^ y; }
};
Having to write these whenever I need them is tedious.
I think they should be part of the standard facility.
Once I wrote a code snippet which looked like this:
std_sup::copy_if(
input.begin(), input.end(), std_sup::default_inserter(output),
boost::compose_f_gx(
std::bind2nd(std::equal_to<unsigned>(), id),
std::bind2nd(std_sup::bitwise_and<unsigned>(), 0xFFFF0000)
)
);
where "std_sup" was a supplementary namespace of my own to "std".
--
KIM Seungbeom <musiphil@bawi.org>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: tslettebo@chello.no.nospam (=?iso-8859-1?Q?Terje_Sletteb=F8?=)
Date: Sun, 29 Jun 2003 21:09:28 +0000 (UTC) Raw View
"KIM Seungbeom" <musiphil@bawi.org> wrote in message
news:bd47bb0e.0306240303.1f261f9b@posting.google.com...
>
> Once I wrote a code snippet which looked like this:
>
> std_sup::copy_if(
> input.begin(), input.end(), std_sup::default_inserter(output),
> boost::compose_f_gx(
> std::bind2nd(std::equal_to<unsigned>(), id),
> std::bind2nd(std_sup::bitwise_and<unsigned>(), 0xFFFF0000)
> )
> );
>
> where "std_sup" was a supplementary namespace of my own to "std".
An alternative is Boost.Lambda:
std_sup::copy_if(input.begin(), input.end(),
std_sup::default_inserter(output), (_1 & 0xFFFF0000) == id);
:)
Regards,
Terje
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: musiphil@bawi.org (KIM Seungbeom)
Date: Mon, 23 Jun 2003 18:29:27 +0000 (UTC) Raw View
I don't see why the bitwise function objects (namely bitwise_and,
bitwise_or and bitwise_xor) are not in the standard. Is there any reason?
Was it a mere mistake, as in the case of copy_if?
Once in a project I had to implement those on my own, a tedious work.
Probably they should be included in the next revision of the standard.
--
KIM Seungbeom <musiphil@bawi.org>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]