Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 28, 2011 Container access in std.container | ||||
---|---|---|---|---|
| ||||
I know that D has some Containers implemented by default( such as a a List, Red-black tree, Array). In C++ these data structures can be used as follows. #include <vector> int main(){ std::vector<int> myVector; std::vector<int>::iterator myIterator; } Then I can use "myIterator" to manipulate "myVector". But in D the containers are embedded in the std.container( as far as I understood it) and I can't do "import std.container" too. So how can I access the built in containers? Thank you..! |
March 28, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ishan Thilina | On 3/28/11 4:17 PM, Ishan Thilina wrote:
> I know that D has some Containers implemented by default( such as a a List,
> Red-black tree, Array). In C++ these data structures can be used as follows.
>
> #include<vector>
>
> int main(){
>
> std::vector<int> myVector;
> std::vector<int>::iterator myIterator;
>
> }
>
> Then I can use "myIterator" to manipulate "myVector".
>
> But in D the containers are embedded in the std.container( as far as I
> understood it) and I can't do "import std.container" too. So how can I access
> the built in containers?
Hi Ishan,
First, to avoid confusion in further discussions, the term »built-in« is usually used when referring to the types which are part of the D language itself (e.g. the built-in arrays and associative arrays, i.e. int[] and int[string]). The types std.container, on the other hand, could be in any other library as well, so I wouldn't call them built-in, but rather just Phobos containers.
What exactly do you mean by »I can't do "import std.container"«? Assuming you have a working D2 environment, you should be able to use them like this:
---
import std.container;
import std.stdio;
void main() {
auto rb = redBlackTree(4, 1, 2, 3);
foreach (e; rb) {
writeln(e);
}
}
---
To get a range over all elements (in an container-defined order), use the slicing operator [], e.g. rb[] – if I remember correctly, the std.container ddoc page has more information on commonly supported operations.
David
|
March 28, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 2011-03-28 07:48, David Nadlinger wrote:
> ---
> import std.container;
> import std.stdio;
>
> void main() {
> auto rb = redBlackTree(4, 1, 2, 3);
> foreach (e; rb) {
> writeln(e);
> }
> }
> ---
I believe that the redBlackTree function is only in the git repository at present (so, it'll be in the next release), so if he's using dmd 2.052, that particular way of creating a RedBlackTree won't work.
- Jonatahn M Davis
|
March 28, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | I am using DGC due to the problems I'm witnessing with DMD. I tried a similar approach. But the following error comes. " structures.d:4: Error: module container cannot read file 'std/container.d' import path[0] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 " I dont know what is wrong. I'll try to compile in Windows and let you know. @David : Thanks for the clarifications :) |
March 29, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ishan Thilina | >I am using GDC due to the problems I'm witnessing with DMD. I tried a similar approach. But the following error comes.
>
>"
>
>structures.d:4: Error: module container cannot read file 'std/container.d' import path[0] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5
>
>"
>
>I dont know what is wrong. I'll try to compile in Windows and let you know.
>
>
A module std.container cannot be found error comes in windows too. I'm using GDC
to compile in linux and DMD to compile in windows. I'm really confused about this :s
|
March 29, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ishan Thilina | Your environment looks wrong. Note that /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 is equivalent to /usr/include/d/4.3.5 so I expect it can't find container.d On 29/03/11 04:54, Ishan Thilina wrote: > I am using DGC due to the problems I'm witnessing with DMD. I tried a similar > approach. But the following error comes. > > " > > structures.d:4: Error: module container cannot read file 'std/container.d' > import path[0] = > /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu > import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 > > " > > I dont know what is wrong. I'll try to compile in Windows and let you know. > > @David : > > Thanks for the clarifications :) |
March 29, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Wawryk | Steven wrote:
>Your environment looks wrong. Note that
>
>/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5
>
>is equivalent to
>
>/usr/include/d/4.3.5
>
>so I expect it can't find container.d
Really sorry for being a burden, I'm new to D. How can I fix this Environment?
|
March 29, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Wawryk | >Your environment looks wrong. Note that
>
>/usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5
>
>is equivalent to
>
>/usr/include/d/4.3.5
I copied container.d to /usr/include/d/4.3.5/std . But the problem is still there :s
|
March 29, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Wawryk | == Quote from Steven Wawryk (stevenw@acres.com.au)'s article > Your environment looks wrong. Note that > /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 > is equivalent to > /usr/include/d/4.3.5 > so I expect it can't find container.d > On 29/03/11 04:54, Ishan Thilina wrote: > > I am using DGC due to the problems I'm witnessing with DMD. I tried a similar approach. But the following error comes. > > > > " > > > > structures.d:4: Error: module container cannot read file 'std/container.d' import path[0] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 > > > > " > > > > I dont know what is wrong. I'll try to compile in Windows and let you know. > > > > @David : > > > > Thanks for the clarifications :) >structures.d:4: Error: module container cannot read file 'std/container.d' import path[0] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5/x86_64-linux-gnu import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5 Ok, now std.container can be imported inside windows. The problem has been that windows has used dmd to compile rather than using dmd2. But I get an error message. I think it's what davis said. >On 2011-03-28 07:48, David Nadlinger wrote: >> --- >> import std.container; >> import std.stdio; >> >> void main() { >> auto rb = redBlackTree(4, 1, 2, 3); >> foreach (e; rb) { >> writeln(e); >> } >> } >> --- >I believe that the redBlackTree function is only in the git repository at present (so, it'll be in the next release), so if he's using dmd 2.052, that particular way of creating a RedBlackTree won't work. So how can I declare a redBlackTree..? It seems that there's no importing problem inside windows now. But the problem still there in Linux. I'm using GDC to compile. |
March 29, 2011 Re: Container access in std.container | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ishan Thilina | >So how can I declare a redBlackTree...?
I'm so sorry for being this much foolish. I found the way to do it( make a redBlackTree). Again I'm really sorry :-/.
now all that is left is the problem with GDC. Why can't I do "import std.container" in Linux :(
|
Copyright © 1999-2021 by the D Language Foundation