Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
eigen
eigen
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 587
    • Issues 587
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Custom Issue Tracker
    • Custom Issue Tracker
  • Merge Requests 18
    • Merge Requests 18
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • libeigen
  • eigeneigen
  • Issues
  • #2086

Closed
Open
Opened Dec 06, 2020 by Haoran Ni@drelatgithub

Indexing map of const vector results in value instead of const reference. Intended or bug?

Version: 3.3.7
Platform: 64-bit Windows

It might be a duplicate but I could not find an issue that describes this. Currently, when I have a map of a constant vector type, the return type for the indexing operation of the map becomes a value type instead of a const reference type. This makes the following example not compile.

VectorXd v1(6);
v1 << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0;

const auto vm = Vector3d::Map(&v1[1]);
const auto vmc = Vector3d::Map(&as_const(v1[1]));

cout << &v1(1) << endl;  // okay, pointer to "2.0"
cout << &vm(1) << endl;  // okay, pointer to "3.0"
cout << &vmc(1) << endl; // error, vmc(1) has type "double" instead of "const double&"

Although I can still get the pointer using vmc.data() + 1, the behavior really got me as a surprise. As a comparison with a standard type that does something similar to Map, an std::span of a constant type, when indexed, gives a const reference instead of a value.

My questions are:

  1. Is this behavior intended or a bug?
  2. If it is intended: is there any reason for this behavior (I thought of striding, alignment, etc, but I cannot convince myself)? If it is a bug: is it possible to correct it?

Thanks!

Assignee
Assign to
4.0
Milestone
4.0
Assign milestone
Time tracking
None
Due date
None
Reference: libeigen/eigen#2086