boost::array as part of container.

hi i would like to know how to insert boost::array into containers such as vectors, list, etc, in an effective and easy way.. tuples don't work cause you can't get to random access index. Thanks. AES word example. typedef boost::array<int, 4> word; std::vector vecOfWord; // perform some word insertion.

chun ping wang wrote:
tuples don't work cause you can't get to random access index.
huh? Tuples give random access. However, only if the index is given at compile time.
AES word example. typedef boost::array<int, 4> word;
std::vector vecOfWord;
std::vector<word> vecOfWord;
// perform some word insertion.
You could do this, for example. word w = {1, 2, 3, 4}; vecOfWord.push_back(w);

On Fri, 24 Nov 2006, Mathias Gaunard wrote:
typedef boost::array<int, 4> word;
std::vector vecOfWord;
std::vector<word> vecOfWord;
// perform some word insertion.
You could do this, for example. word w = {1, 2, 3, 4};
vecOfWord.push_back(w);
I have often encountered a similar situation, which led me to think that maybe we should have the equivalent of make_tuple for boost::arrays, e.g. make_array. Example: vecOfWord.push_back( make_array( 1 , 2 , 3 , 4 ) ) ; -- François Duranleau LIGUM, Université de Montréal

chun ping wang wrote:
hi i would like to know how to insert boost::array into containers such as vectors, list, etc, in an effective and easy way.. tuples don't work cause you can't get to random access index. Thanks.
AES word example. typedef boost::array<int, 4> word;
std::vector vecOfWord;
// perform some word insertion. ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users #include <boost/array.hpp>
#include <algorithm> #include <iostream> #include <vector> using namespace std; using namespace boost; int main( int argc, char * argv[] ) { array<int, 5> a = {0, 1, 2, 3, 4}; vector<int> v(a.begin(), a.end()); copy(v.begin(), v.end(), ostream_iterator<int>(cout, "\n")); return 0; } -- HTH dave

sorry i want to know how to insert them not to how to copy tehm . like Container of boost of array . vector<boost::array<int, 4> > v; v.push_back({4, 9, 11, 19}); On 11/24/06, David Klein <dave_chp@gmx.de> wrote:
chun ping wang wrote:
hi i would like to know how to insert boost::array into containers such as vectors, list, etc, in an effective and easy way.. tuples don't work cause you can't get to random access index. Thanks.
AES word example. typedef boost::array<int, 4> word;
std::vector vecOfWord;
// perform some word insertion. ------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users #include <boost/array.hpp>
#include <algorithm> #include <iostream> #include <vector>
using namespace std; using namespace boost;
int main( int argc, char * argv[] ) { array<int, 5> a = {0, 1, 2, 3, 4}; vector<int> v(a.begin(), a.end());
copy(v.begin(), v.end(), ostream_iterator<int>(cout, "\n")); return 0; }
-- HTH dave
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

sorry i want to know how to insert them not to how to copy tehm . like Container of boost of array .
vector<boost::array<int, 4> > v; v.push_back({4, 9, 11, 19});
chun ping wang wrote: this line: vector<int> v(a.begin(), a.end()); actually creates a vector with the data of the array. the copy(...) line was just "a test" to show that the content of v was 1, 2, 3, 4... array<int, 4> a = {0, 1, 2, 3}; // create int array with values 0 ... 3 vector<int> v(a.begin(), a.end()); // create vector and copy values from array to vector the "blabla copy" line would be equal to for (size_t loop = 0; loop < v.size(); ++loop) { cout << loop << "\n"; } is this what you ment, or else i'm sorry, i'm missing your point? -- regards, dave

chun ping wang wrote:
vector<boost::array<int, 4> > v; v.push_back({4, 9, 11, 19});
I already gave you an example. You need to use an intermediate variable. You could also do this to prevent copying: v.resize(v.size()+1); v[v.size()-1][0] = 4; v[v.size()-1][1] = 9; v[v.size()-1][2] = 11; v[v.size()-1][3] = 19;

yeah thanks, for the help. Hmm now i run into another problem.. probably more so to do with c++ language. template <class T> class AES { private: static const boost::array<T, 30> Rcon = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 }; }; // 19 C:\CPW\cs classes\cs512\c++\AES.hpp a brace-enclosed initializer is not allowed here before '{' token On 11/25/06, Mathias Gaunard <mathias.gaunard@etu.u-bordeaux1.fr> wrote:
chun ping wang wrote:
vector<boost::array<int, 4> > v; v.push_back({4, 9, 11, 19});
I already gave you an example. You need to use an intermediate variable.
You could also do this to prevent copying:
v.resize(v.size()+1);
v[v.size()-1][0] = 4; v[v.size()-1][1] = 9; v[v.size()-1][2] = 11; v[v.size()-1][3] = 19;
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

chun ping wang wrote:
Hmm now i run into another problem.. probably more so to do with c++ language. template <class T> class AES { private: static const boost::array<T, 30> Rcon = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 };
};
// 19 C:\CPW\cs classes\cs512\c++\AES.hpp a brace-enclosed initializer is not allowed here before '{' token
The compiler is right. Try something like this: template <class T> class AES { private: static const boost::array<T, 30> Rcon; }; template <typename T> const boost::array<T, 30> AES<T>::Rcon = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91 }; Greetings from Bremen, Daniel Krügler
participants (5)
-
chun ping wang
-
Daniel Krügler
-
David Klein
-
François Duranleau
-
Mathias Gaunard