digitalmars.D.learn - Container access in std.container
- Ishan Thilina (12/12) Mar 28 2011 I know that D has some Containers implemented by default( such as a a Li...
- David Nadlinger (26/37) Mar 28 2011 Hi Ishan,
- Jonathan M Davis (5/16) Mar 28 2011 I believe that the redBlackTree function is only in the git repository a...
- Ishan Thilina (11/11) Mar 28 2011 I am using DGC due to the problems I'm witnessing with DMD. I tried a si...
- Ishan Thilina (2/11) Mar 28 2011 A module std.container cannot be found error comes in windows too. I'm u...
- Steven Wawryk (6/17) Mar 28 2011 Your environment looks wrong. Note that
- Ishan Thilina (2/7) Mar 28 2011 Really sorry for being a burden, I'm new to D. How can I fix this Enviro...
- Ishan Thilina (1/5) Mar 28 2011 I copied container.d to /usr/include/d/4.3.5/std . But the problem is st...
- Ishan Thilina (7/49) Mar 29 2011 Ok, now std.container can be imported inside windows. The problem has be...
- Ishan Thilina (4/5) Mar 29 2011 I'm so sorry for being this much foolish. I found the way to do it( make...
- Jonathan M Davis (8/15) Mar 29 2011 Unless you really need gdc, I'd just suggest using dmd. It's quite easy ...
- Jonathan M Davis (8/15) Mar 29 2011 Unless you really need gdc, I'd just suggest using dmd. It's quite easy ...
- Ishan Thilina (4/11) Mar 29 2011 I'm using GDC because I can't use DMD in linux. I have started a seperat...
- spir (13/15) Mar 29 2011 I'm using dmd on Linux without any issue. But only stable releases (seve...
- Daniel Green (4/6) Mar 29 2011 std.container is a D2 module. Based on your include path you have a D1
- Jonathan M Davis (17/83) Mar 29 2011 I believe that you'd just do
- Steven Schveighoffer (6/11) Mar 29 2011 I think:
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..!
Mar 28 2011
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
Mar 28 2011
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
Mar 28 2011
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 :)
Mar 28 2011
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
Mar 28 2011
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 :)
Mar 28 2011
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.dReally sorry for being a burden, I'm new to D. How can I fix this Environment?
Mar 28 2011
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.5I copied container.d to /usr/include/d/4.3.5/std . But the problem is still there :s
Mar 28 2011
== Quote from Steven Wawryk (stevenw acres.com.au)'s articleYour 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.5Ok, 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.
Mar 29 2011
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 :(
Mar 29 2011
On 2011-03-29 01:45, Ishan Thilina wrote:Unless you really need gdc, I'd just suggest using dmd. It's quite easy to get working. You just unzip it wherever you want it and add /path/to/unzipped/dmd2/linux/bin to your path, and it works. I have no clue what it takes to get gdc to work. And the only advantage to gdc I'm aware of is that its backend tends to generate more efficient code than dmd's currently does. - Jonathan M DavisSo 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 :(
Mar 29 2011
On 2011-03-29 01:45, Ishan Thilina wrote:Unless you really need gdc, I'd just suggest using dmd. It's quite easy to get working. You just unzip it wherever you want it and add /path/to/unzipped/dmd2/linux/bin to your path, and it works. I have no clue what it takes to get gdc to work. And the only advantage to gdc I'm aware of is that its backend tends to generate more efficient code than dmd's currently does. - Jonathan M DavisSo 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 :(
Mar 29 2011
Unless you really need gdc, I'd just suggest using dmd. It's quite easy to get working. You just unzip it wherever you want it and add /path/to/unzipped/dmd2/linux/bin to your path, and it works. I have no clue what it takes to get gdc to work. And the only advantage to gdc I'm aware of is that its backend tends to generate more efficient code than dmd's currently does. - Jonathan M DavisI'm using GDC because I can't use DMD in linux. I have started a seperate thread for that. Here it is. http://www.mail-archive.com/digitalmars-d-learn puremagic.com/msg11525.html
Mar 29 2011
On 03/29/2011 12:43 PM, Ishan Thilina wrote:I'm using GDC because I can't use DMD in linux. I have started a seperate thread for that.I'm using dmd on Linux without any issue. But only stable releases (several versions have passed). May I suggest you take some time to uninstall everything properly, then install again from scratch according to the online guidelines: downloads: http://www.digitalmars.com/d/download.html win: http://www.digitalmars.com/d/2.0/dmd-windows.html linux: http://www.digitalmars.com/d/2.0/dmd-linux.html Denis -- _________________ vita es estrany spir.wikidot.com
Mar 29 2011
On 3/29/2011 4:45 AM, Ishan Thilina wrote:now all that is left is the problem with GDC. Why can't I do "import std.container" in Linux :(std.container is a D2 module. Based on your include path you have a D1 version of GDC. GDC uses include/d for D1 and include/d2 for D2.
Mar 29 2011
On 2011-03-29 01:38, Ishan Thilina wrote:== Quote from Steven Wawryk (stevenw acres.com.au)'s articleI believe that you'd just do auto rb = RedBlackTree(4, 1, 2, 3); The problem with the version in dmd 2.052 though is that you can declare one if there isn't anything in it. Or at least, if you do, you'll run into problems, because it won't have been properly initialized (due to the lack of default constructor). The version in git (which can be gotten here if you want to try it out: https://github.com/D-Programming-Language/phobos/ - though given how much trouble that you've been having getting dmd to work, I'm not sure that you want to try building druntime and Phobos yourself) changes RedBlackTree to a class, which fixes the problem. And by adding the function redBlackTree, it manages to make creating one a lot more flexible. The current version should work just fine though. It just isn't quite as nice (but the first version of Phobos with RedBlackTree was either 2.051 or 2.052, so it's a quite recent addition to std.container). - Jonathan M DavisYour 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: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.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-lin ux-gnu import path[1] = /usr/lib/gcc/x86_64-linux-gnu/4.3.5/../../../../include/d/4.3.5On 2011-03-28 07:48, David Nadlinger wrote: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.--- 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.
Mar 29 2011
On Tue, 29 Mar 2011 04:49:41 -0400, Jonathan M Davis <jmdavisProg gmx.com> wrote:On 2011-03-29 01:38, Ishan Thilina wrote:I think: auto rb = RedBlackTree!(int)(4, 1, 2, 3); But the version in git will be much nicer. -SteveSo how can I declare a redBlackTree..?I believe that you'd just do auto rb = RedBlackTree(4, 1, 2, 3);
Mar 29 2011