Closed apoorv-2204 closed 1 year ago
This link describes the C++ STL.
Among others, it states that:
Some of the key components of the STL include:
- Containers: The STL provides a range of containers, such as vector, list, map, set, and stack, which can be used to store and manipulate data.
- Algorithms: The STL provides a range of algorithms, such as sort, find, and binary_search, which can be used to manipulate data stored in containers.
- Iterators: Iterators are objects that provide a way to traverse the elements of a container. The STL provides a range of iterators, such as forward_iterator, bidirectional_iterator, and random_access_iterator, that can be used with different types of containers.
- Function Objects: Function objects, also known as functors, are objects that can be used as function arguments to algorithms. They provide a way to pass a function to an algorithm, allowing you to customize its behavior.
- Adapters: Adapters are components that modify the behavior of other components in the STL. For example, the reverse_iterator adapter can be used to reverse the order of elements in a container.
In Rust:
Vec
, for instance).BTreeMap
, HashMap
, BinaryHeap
, LinkedList
, Option
, BTreeSet
, Vec
, VecDecque
, HashSet
, Result
, arrays
, slices
...)In short, what you are looking for is already part of the Rust Standard Library.
This link describes the C++ STL.
Among others, it states that:
Some of the key components of the STL include:
- Containers: The STL provides a range of containers, such as vector, list, map, set, and stack, which can be used to store and manipulate data.
- Algorithms: The STL provides a range of algorithms, such as sort, find, and binary_search, which can be used to manipulate data stored in containers.
- Iterators: Iterators are objects that provide a way to traverse the elements of a container. The STL provides a range of iterators, such as forward_iterator, bidirectional_iterator, and random_access_iterator, that can be used with different types of containers.
- Function Objects: Function objects, also known as functors, are objects that can be used as function arguments to algorithms. They provide a way to pass a function to an algorithm, allowing you to customize its behavior.
- Adapters: Adapters are components that modify the behavior of other components in the STL. For example, the reverse_iterator adapter can be used to reverse the order of elements in a container.
In Rust:
- Containers are called Collections
- Algorithms are usually implemented on slices which enables you to call them on any type that implements the adequate trait. This is why you can call sort or binary_search or any other slice method on an array or a
Vec
, for instance).- Iterator is a trait and you can get an iterator out of any collection that implements the IntoIterator trait. The standard library implements it for you for all standard collections (
BTreeMap
,HashMap
,BinaryHeap
,LinkedList
,Option
,BTreeSet
,Vec
,VecDecque
,HashSet
,Result
,arrays
,slices
...)- Function Objects are called closures or function pointers and are described by 3 standard traits: Fn, FnMut and FnOnce.
- Adapters are generally available as methods associated to the structures they refer to. See the rev iterator method, the iterator reverse method or also the Reverse adapter...
In short, what you are looking for is already part of the Rust Standard Library.
So I can say goodbye to C++? as everything is there in Rust already part of the standard library ? we dont need any crates?. Beacuse in online judjes like codechef, leetcode, spoj, codeforces, they dont allow crates.
Well, I really couldn't say, it depends on what you intend to do but a lot of people already use Rust for competitive programming. There even is an advent_of_code crate for instance, and you can find many other examples.
On the other hand, it's a little weird to me that you're asking for a "batteries-included competitive programming language" because it sounds like you're looking for a language that will give you an advantage over your competitors.
I personally believe that Rust and its ecosystem will help anyone be more productive but in the end, only you can answer that question by trying it. Be aware that the learning curve is a little steeper than for other languages, though.
All that aside, this is a discussion forum for Rustlings. Your question might be better suited to one of the more general discussion forums, such as the Users forum. Closing this as off-topic.
Well, I really couldn't say, it depends on what you intend to do but a lot of people already use Rust for competitive programming. There even is an advent_of_code crate for instance, and you can find many other examples.
On the other hand, it's a little weird to me that you're asking for a "batteries-included competitive programming language" because it sounds like you're looking for a language that will give you an advantage over your competitors.
I personally believe that Rust and its ecosystem will help anyone be more productive but in the end, only you can answer that question by trying it. Be aware that the learning curve is a little steeper than for other languages, though.
sounds like you're looking for a language that will give you an advantage over your competitors.
I hope you are not oblivious to the original question.
All that aside, this is a discussion forum for Rustlings. Your question might be better suited to one of the more general discussion forums, such as the Users forum. Closing this as off-topic.
Right, I really needed to have an insight. I just dont want to go back to C++.
Thank you everyone!
do we have c++ stl equivalent in rust?? Can we completely switch to Rust for competitive programming? or stick with c++