Category: C++ । সি প্লাস প্লাস

Print minimum, maximum, and sum of the valarray

/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/print-minimum-maximum-and-sum-of-the-valarray/

valarray slice

/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/valarray-slice/

Call member function for each element in vector

/* The following code example is taken from the book * “The C++ Standard Library – A Tutorial and Reference” * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in …

Continue reading

Permanent link to this article: http://bangla.sitestree.com/%e0%a6%ad%e0%a7%87%e0%a6%95%e0%a7%8d%e0%a6%9f%e0%a6%b0-%e0%a6%8f%e0%a6%b2%e0%a6%bf%e0%a6%ae%e0%a7%87%e0%a6%a8%e0%a7%8d%e0%a6%9f-%e0%a6%8f%e0%a6%b0-%e0%a6%b8%e0%a7%87%e0%a6%b2-%e0%a6%a8%e0%a6%be/

Use bitset with enum together

/* The following code example is taken from the book  * “The C++ Standard Library – A Tutorial and Reference”  * by Nicolai M. Josuttis, Addison-Wesley, 1999  *  * (C) Copyright Nicolai M. Josuttis 1999.  * Permission to copy, use, modify, sell and distribute this software  * is granted provided this copyright notice appears in all copies.  * This software is provided “as is” without express or implied  * warranty, and with no claim as to its suitability for any purpose.  */ #include <bitset> #include <iostream> using namespace std; int main() {     /* enumeration type for the bits      * – each bit represents a color      */     enum Color { red, yellow, green, blue, white, black, //…,                  numColors };     // create bitset for all bits/colors     bitset<numColors> usedColors;     // set bits for two colors     usedColors.set(red);     usedColors.set(blue);     // print some bitset data     cout << “bitfield of used colors:   ” << usedColors          << endl;     cout << “number   of used colors:   ” << usedColors.count()          << endl;     cout << “bitfield of unused colors: ” << ~usedColors          << endl;     // if any color is used     if (usedColors.any()) {         // loop over all colors         for (int c = 0; c < numColors; ++c) {             // if the actual color is used             if (usedColors[(Color)c]) {                 //…             }         }     } } /*  bitfield of used colors:   001001 number   of used colors:   2 bitfield of unused colors: 110110  */

Permanent link to this article: http://bangla.sitestree.com/use-bitset-with-enum-together/