473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Generic container?

I am writing a container C to be used in a generic library (template
library). C are supposed to contain points in either 1,2 or 3 dimension (x),
(x,y) or (x,y,z).

My first thought was to use a std::vector containing structs with either
one, two or three fields (depending on dimension) but are there any better
ways to implement C when the code using it should not care what kind of
dimension is used?
Aug 2 '08 #1
1 1602
On Aug 2, 12:43*pm, "saneman" <as...@asd.comwrote:
I am writing a container C to be used in a generic library (template
library). C are supposed to contain points in either 1,2 or 3 dimension (x),
(x,y) or (x,y,z).

My first thought was to use a std::vector containing structs with *either
one, two or three fields (depending on dimension) but are there any better
ways to implement C when the code using it should not care what kind of
dimension is used?
Dear Saneman
Hi

I know, my solution has some restrictions, but may be it helps:

template<class T = int, int Dim = 1>
struct Point {
T Coord[Dim];
// constructor. ,,,
Point() {
for (int i = 0; i < Dim; i++) Coord[i] = T();
}
T GetCoord(int d) { if (d < Dim) return Coord[d]; }
void SetCoord(T t, int d) { if (d < Dim) Coord[d] = t; }
};

template<class T = Point<
struct Container {
Container(int sz = 1) { V.clear(); for (int i = 0; i < sz; i++)
V.push_back(T()); }
std::vector<TV;
};

Regards,
Saeed Amrollahi
Aug 2 '08 #2

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

Similar topics

1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
1
by: Stewart Rogers | last post by:
Hi all, I have been working on an ASP.NET application that is a kind of wizard ( a list of sequential pages ). We built that application for the CLIENT-A and it worked fine. After six months...
2
by: Luc Claustres | last post by:
I have a generic container such as: template<class T> class Container { // some data structure that store elements of type T } I use this container in a hierarchical manner, that is...
19
by: Nafai | last post by:
Hi I want to write a function which erases al the repeated elements in a range. How should be the prototype? template <class Iterator> void eraseRepeated(Iterator begin, Iterator end); ...
5
by: Alberto Giménez | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I have a simple question, and after a *very long* google search I still can't get it. It's about generic abstract data types (for...
0
by: sda | last post by:
Hi everybody, I have a problem to fire an event in a DataGrid. 1/ I have got a datagrid in a generic user control protected System.Web.UI.WebControls.DataGrid dgListDataGrid; ........ ...
4
by: Jethro Guo | last post by:
C++ template use constraint by signature,It's very flexible to programmer but complex for complier, and at most time programmer can not get clear error message from complier if error occur. C#...
4
by: Mitchel Haas | last post by:
Hello, Feeling a need for a generic tree container to supplement the available containers in the STL, I've created a generic tree container library (TCL). The library usage is very much like...
6
by: Rennie deGraaf | last post by:
Hello, I would like to write a function that reads a sequence of unsigned shorts from /any/ container, converts them to pairs of unsigned chars, and writes them to /any/ container. In other...
4
by: Terence Wilson | last post by:
I'm having trouble designing a container for all the basic types(char, int, float, double). The container should be able to hold contiguous arrays of type T. I would like some kind of generic...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.