question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Request] support subscript `[]`operator overloading

See original GitHub issue

Recently operator overloading was added, operations like +, -, *, / amongst other things were added. I noticed however that [] was not a part of this change, and was wondering if it were possible to add.

Basically, it should functions basically how get/set works, for list, map, and other custom objects, accepting the key type and either returning a value or set the value.

List<String> strList = ...;

strList[0]; // List#get(int)
strList[0] = "Hello"; // List#set(int, String)

Map<String, Value> strMap = ...;

strMap["Put"] = new Value(...); // Map#put(String, Value)
strMap["Get"]; // Map#get(String)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rsmckinneycommented, Oct 16, 2019

@Frontear Several additional operators are under consideration, these include:

  • increment/decrement: ++ and --
  • compound assignment: +=, *=, etc.
  • subscript: [], [] = If implemented, a[x] compiles as a.get(x), and a[x] = b compiles as a.set(x, b). Note you could add extension methods to existing classes to satisfy get/set methods e.g., add set(K, V) to Map, which delegates to put(K, V).
0reactions
rsmckinneycommented, Nov 15, 2020

Release 2020.1.34 implements operator overloading for:

  • prefix/postfix increment/decrement operators ++ and --
  • compound assignment: operators +=, -=, *=, /=, %=,
  • index operator [], both access and assignment

Please see Operator Overloading documentation for details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

14.9 — Overloading the subscript operator - Learn C++
The subscript operator is one of the operators that must be overloaded as a member function. An overloaded operator[] function will always take ......
Read more >
Overloading Subscript or array index operator [] in C++
The Subscript or Array Index Operator is denoted by '[]'. This operator is generally used with arrays to retrieve and manipulate the array ......
Read more >
Subscripting [] Operator Overloading in C++ - Tutorialspoint
The subscript operator [] is normally used to access array elements. This operator can be overloaded to enhance the existing functionality of C++...
Read more >
Overloading subscript operator for non-array elements
As stated in the reference, std::vector<bool> it returns a proxy class that has its operators overloaded to act as an element of the...
Read more >
Operator Overloading, C++ FAQ - Standard C++
Operator overloading allows C/C++ operators to have user-defined meanings on user-defined types (classes). Overloaded operators are syntactic sugar for function ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found