Hello,
It is not possible to assign values to, say, a vector<float[3]> due to the
fact that arrays are not assignable.
Theoretically there's a simple workaround which involves wrapping the array
in a struct, e.g.
struct float3
{
float m[3];
};
....and then using vector<float3>
The problem with this approach is, that there's no guarantee that
sizeof(float[3]) == sizeof(float3).
My question boils down to: is there any non-contrived generic way to treat
containers of array types in an analogous way to non-array types?
Cheers,
b
--
:: bartekd [at] o2 [dot] pl 2 1309
bartek wrote: It is not possible to assign values to, say, a vector<float[3]> due to the fact that arrays are not assignable.
I think it's actually stricter than that. You just cannot have
vector<float[3]>, period.
Theoretically there's a simple workaround which involves wrapping the array in a struct, e.g.
struct float3 { float m[3]; };
...and then using vector<float3>
Why "theoretically" ? It's a work-around. Work-arounds are always
practical, not theoretical.
The problem with this approach is, that there's no guarantee that sizeof(float[3]) == sizeof(float3).
Why do you think it's a problem? sizeof(float3:: m) == sizeof(float[3])
What doesn't the difference in sizes between the struct and its member
let you achieve? Are you concerned with the fact that an array of, say,
10 float3 will not be the same as 10*3*sizeof(flo at)? Is that _really_
so important? Why? Do you need to read an array (vector's storage) of
those structs in one huge 'read' operation? Can you not split it into
several smaller ones? My question boils down to: is there any non-contrived generic way to treat containers of array types in an analogous way to non-array types?
Well, where standard containers are concerned, there are no "containers
of array types". If you devise your own container (that doesn't have to
satisfy container requirements put forth by the Standard), you can have
whatever you want, and it's probably not going to be "contrived" (whatever
you mean by that).
Victor
Victor Bazarov <v.********@com Acast.net> wrote in
news:V3******** *******@newsrea d1.dllstx09.us. to.verio.net: bartek wrote: It is not possible to assign values to, say, a vector<float[3]> due to the fact that arrays are not assignable.
I think it's actually stricter than that. You just cannot have vector<float[3]>, period.
Theoretically there's a simple workaround which involves wrapping the array in a struct, e.g.
struct float3 { float m[3]; };
...and then using vector<float3>
Why "theoretically" ? It's a work-around. Work-arounds are always practical, not theoretical.
Theoretically for me. Some workarounds are more practical than others.
See below. The problem with this approach is, that there's no guarantee that sizeof(float[3]) == sizeof(float3).
Why do you think it's a problem? sizeof(float3:: m) == sizeof(float[3]) What doesn't the difference in sizes between the struct and its member let you achieve? Are you concerned with the fact that an array of, say, 10 float3 will not be the same as 10*3*sizeof(flo at)? Is that _really_ so important? Why? Do you need to read an array (vector's storage) of those structs in one huge 'read' operation? Can you not split it into several smaller ones?
I'm dealing with a C API which uses pointers to arrays of arrays all
around its interfaces.
Those arrays are usually quite big. Therefore I want to keep them in my
C++ code in a binary compatible fashion, so I can get rid of wasteful
copying on the API boundary, and just pass a &*data.begin (). My question boils down to: is there any non-contrived generic way to treat containers of array types in an analogous way to non-array types?
Well, where standard containers are concerned, there are no "containers of array types". If you devise your own container (that doesn't have to satisfy container requirements put forth by the Standard), you can have whatever you want, and it's probably not going to be "contrived" (whatever you mean by that).
Thanks. It seems throwing together a custom container is the way to go.
Cheers.
--
:: bartekd [at] o2 [dot] pl This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rowan |
last post by:
Greetings:
I need some guidance. I have been using UDT's and arrays to hold
information so I can easily display data and save it. I am in the
process of building a new form and ran across a problem I can't figure
out how to solve.
I have a UDT as follows:
Public Type udtBL
|
by: Juicer_X |
last post by:
Hello,
I have some code that I'm working on, the problem isn't that it doesn't
work it's that it's too slow. I have a class that holds my homemade class
within an std::map, within an std::map. here is the declaration.
std::map<char, std::map<char, CWordFrequency> > baseMap;
Now I can assign a pointer to the inner map, but I cannot assign a
pointer to my class without actually copying the second map into memory. I'm
|
by: Ares Lagae |
last post by:
Hello,
I am trying to create a container the stl way, and I have a couple of
questions. The code of the container in question can be found at
http://www.cs.kuleuven.ac.be/~ares/tmp/array_2_hpp.html
It is a 2d array that dynamically allocates its storage. It cannot be
resized. It offers element access methods for both sequential access and 2d
element access.
|
by: phil_gg04 |
last post by:
Dear C++ Experts,
Over the last couple of months I have been writing my first program
using shared memory. It has been something of an "in-at-the-deep-end"
experience, to say the least. At present the shared memory contains a
few fixed-size structs, but I really need to be able to store more
complex variable-sized data in there. So the next task is to work out
how to store C++ objects, and if possible STL containers, in this
shared...
|
by: BigMan |
last post by:
Which is the preferred way to create a const container in general:
1. container_type< value_type > const; or
2. container_type< value_type const >?
| |
by: Ross A. Finlayson |
last post by:
I'm trying to write some C code, but I want to use C++'s std::vector.
Indeed, if the code is compiled as C++, I want the container to
actually be std::vector, in this case of a collection of value types or
std::vector<int>.
So where I would use an int* and reallocate it from time to time in C,
and randomly access it via , then I figure to copy the capacity and
reserve methods, because I just need a growable array.
I get to considering...
|
by: moleskyca1 |
last post by:
I've ran into a problem with inheritance and STL containers. The code
is too much to list, but here is the basic problem:
#include <queue>
using namespace std;
class Base
{
public:
|
by: jimxoch |
last post by:
Hi list,
Most STL containers are storing their data on the heap. (although some
std::string implementations are notable exceptions) Of course, using
the heap as storage increases flexibility and allows the handling of
much bigger amounts of data. However, there are cases where this turns
out to be inefficient for at least two reasons: A) Allocations and
deallocations on heap are much slower. B) Memory access on stack is
more cache...
|
by: massysett |
last post by:
Greetings,
Having classes with member objects that have STL containers of objects
whose definitions are incomplete results in undefined behavior. See
for example:
http://www.ddj.com/database/184403814#8
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.14
I am wondering: is it okay to have member functions that return an STL
|
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...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |