Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List.end().value should throw an out_of_range error #54

Closed
samchon opened this issue Dec 12, 2019 · 0 comments
Closed

List.end().value should throw an out_of_range error #54

samchon opened this issue Dec 12, 2019 · 0 comments
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request

Comments

@samchon
Copy link
Owner

samchon commented Dec 12, 2019

Summary

  • TSTL version: 2.3.0
  • Expected behavior: accessing to List.end().value throws an out_of_range error
  • Actual behavior: accessing to List.end().value is possible (initial value: undefined)

Code occuring the bug

import { List } from "tstl";

function main(): void
{
    let l: List<number> = new List();

    l.end().value; // No error, but returns undefined
    l.end().value = 3; // No error, but possible
}
main();

Detailed Story

When accessing to Vector.end().value, it throws an out_of_range error. However, the List.end().value does not throw the out_of_range exception. It returns the undefined value. Even configuring is to the List.end().value is also possible.

This story is also applicable to the ForwardList and even associate containers like HashSet and TreeMultiMap. The associative containers, they manage elements using the List container. Therefore, if an user try to access mapped-value to the end position like Associative.end().second, the error message would be JS native error; Cannot set property 'second' of undefined. The native error message can't represent the exact reason and situation.

To keep the consistency and immediacy, I believe that the List should throw an out_of_range error when accessing to the List.end().value, even though it's not the regular spec of C++/STL standard.

import { TreeMap } from "tstl";

function main(): void
{
    let m: TreeMap<number, string> = new TreeMap();
    m.end().second = "something"; 
        // Error.message -> Cannot set property 'second' of undefined
        // throwing out_of_range error would be much eloquent
}
@samchon samchon added the enhancement New feature or request label Dec 12, 2019
@samchon samchon self-assigned this Dec 12, 2019
@samchon samchon added the bug Something isn't working label Dec 12, 2019
@samchon samchon changed the title base.ListIterator.end().value throws an out_of_range base.ListIterator.end().value should throw an out_of_range error Dec 12, 2019
@samchon samchon changed the title base.ListIterator.end().value should throw an out_of_range error List.end().value should throw an out_of_range error Dec 12, 2019
@samchon samchon added the experimental Experimental Feature label Dec 12, 2019
@samchon samchon added this to To do in v2.3 Update Dec 12, 2019
@samchon samchon added this to To do in v2.4 Update Dec 12, 2019
@samchon samchon moved this from To do to In progress in v2.3 Update Dec 12, 2019
@samchon samchon moved this from To do to Done in v2.4 Update Dec 12, 2019
@samchon samchon moved this from In progress to Patch in v2.3 Update Dec 12, 2019
@samchon samchon added documentation Improvements or additions to documentation and removed experimental Experimental Feature labels Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation enhancement New feature or request
Projects
v2.4 Update
  
Done
v2.3 Update
  
Patch
Development

No branches or pull requests

1 participant